function ch

    figure(...
        'MenuBar', 'None', ...
        'Name', 'Chess', ...
        'NumberTitle', 'off');
    
    cameratoolbar;


[V0, F0] = ellipse(0, 15, 15, 32);

[V1, F] = roundcone(15, 15);
V1 = scaletranslate(V1, 2, 0);

[V2, F] = roundcone(15, 13);
V2 = scaletranslate(V2, 2, 2);

[V3, F] = roundcone(13, 15);
V3 = scaletranslate(V3, 2, 4);

[V4, F] = roundcone(15, 15);
V4 = scaletranslate(V4, 1, 6);

[V5, F] = roundcone(15, 10);
V5 = scaletranslate(V5, 6, 7);

[V6, F] = roundcone(10, 10);
V6 = scaletranslate(V6, 4, 13);

[V7, F] = roundcone(10, 5);
V7 = scaletranslate(V7, 20, 17);

[V8, F] = roundcone(5, 12);
V8 = scaletranslate(V8, 2, 37);

[V9, F] = roundcone(12, 8);
V9 = scaletranslate(V9, 2, 39);

[V10, F] = roundcone(8, 8);
V10 = scaletranslate(V10, 2, 41);

[V11, F] = roundcone(8, 6);
V11 = scaletranslate(V11, 2, 43);

[V12, F] = roundcone(6, 6);
V12 = scaletranslate(V12, 3, 45);

[V13, F] = roundcone(6, 7);
V13 = scaletranslate(V13, 1, 48);

[V14, F] = roundcone(7, 6);
V14 = scaletranslate(V14, 1, 49);

[V15, F] = roundcone(6, 11);
V15 = scaletranslate(V15, 9, 50);

[V16, F] = roundcone(11, 2);
V16 = scaletranslate(V16, 2, 59);

[V17, F] = roundcone(2, 2);
V17 = scaletranslate(V17, 2, 61);

[V18, F18] = ellipse(1, 2, 2, 32);
V18 = translate(V18, [0, 0, 63]);

[V19, F19] = ellipsoide(0, 3, 3, 3, 32, 32);
V19 = translate(V19, [0, 0, 66]);

[V, F] = combine(V1, F, V2, F, V3, F, V4, F, V5, F, V6, F, V7, F, ...
    V8, F, V9, F, V10, F, V11, F, V12, F, V13, F, V14, F, V15, F, ...
    V16, F, V17, F, V18, F18);

% Black Queen

w = [1, .7, 0];

draw3d(V0, F0, 'k');
draw3d(V, F, 'k');
draw3d(V19, F19, w);

% Reflection

Vm = [V(:, 1), V(:, 2), -V(:, 3)];
draw3d(Vm, F, 'k');
V19m = [V19(:, 1), V19(:, 2), -V19(:, 3)];
draw3d(V19m, F19, w);

% Shadow
% If 'FaceAlpha'<1 the following does not work correctly:
% two transparent objects (shadow and floor) are too near each to other (?)

Vsh = projection(V);
draw3d(Vsh, F, [.1, .05, 0], 'FaceAlpha', .7, 'SpecularStrength', 0);
V19sh = projection(V19);
draw3d(V19sh, F19, [.1, .05, 0], 'FaceAlpha', .7, 'SpecularStrength', 0);

% White Queen

shift = [40, 0, 0];
V0w = translate(V0, shift);
Vw = translate(V, shift);
V19w = translate(V19, shift);
draw3d(V0w, F0, w);
draw3d(Vw, F, w);
draw3d(V19w, F19, 'k');

% Reflection

Vwm = [Vw(:, 1), Vw(:, 2), -Vw(:, 3)];
draw3d(Vwm, F, w);
V19wm = [V19w(:, 1), V19w(:, 2), -V19w(:, 3)];
draw3d(V19wm, F19, 'k');

% Shadow

Vwsh = projection(Vw);
draw3d(Vwsh, F, [.1, .05, 0], 'FaceAlpha', 1, 'SpecularStrength', 0);
V19wsh = projection(V19w);
draw3d(V19wsh, F19, [.1, .05, 0], 'FaceAlpha', 1, 'SpecularStrength', 0);

% Floor

ambientcolor = .5 * [.3, .1, 0];
x = [-130, 170];
y = [-150, 150];
[X, Y] = meshgrid(x([1, 1, 2, 2]), y([1, 1, 2, 2]));
z = -10;
Z = [z, z, z, z; z, 0, 0, z; z, 0, 0, z; z, z, z, z];
load walnut;
walnut = repmat(walnut, 3, 3);
surface(X, Y, Z, ...
    'CData', walnut, 'FaceColor', 'TextureMap', 'EdgeColor', 'None', ...
    'FaceAlpha', 'Texture', 'AlphaData', sum(walnut, 3)/3);

zl = -70;
Z = [z, z, z, z; z, zl, zl, z; z, zl, zl, z; z, z, z, z];
surface(X, Y, Z, 'FaceColor', ambientcolor, 'EdgeColor', 'None', ...
    'AmbientStrength', 1, 'DiffuseStrength', 0, 'SpecularStrength', 0);

set(gcf, 'Color', ambientcolor);
set(gca, 'Color', ambientcolor, 'Position', [0, 0, 1, 1]);
xlim(x);
ylim(y);
zlim([zl, Inf]);
axis off;

% Light 

camlight headlight;

% Camera moving

tic
tau = .005;

camproj('Perspective');

cam0 = [0, -630, 400];
target0 = [21, -5, 7];
target1 = [21, -5, 30];
campos(cam0);
camtarget(target0)

a = cam0(2);
b = cam0(2);
c = cam0(3);

for t = 3:-tau:1
    cam = [a*t*sin(2*pi*t), b*t*cos(2*pi*t), c*t];
    campos(cam);
    drawnow;
end;

for t = 1:-tau:0
    cam = [a*sin(2*pi*t), b*cos(2*pi*t), c];
    campos(cam);
    drawnow;
end;

function [V, F] = roundcone(R, r)
  [V, F] = cone(R, R, r, r, 5, 32);
  
  
function [V] = scaletranslate(V, sc, tr);
V = scale(V, sc);
V = translate(V, [0, 0, tr]);
      
  
