// Last edited on DATE TIME by USER
// Processed by remove-cam-lights

#include "textures.inc"

background{ color rgb < 0.75, 0.80, 0.85 > }

#declare tx_carro =
  texture{
    pigment{ color rgb < 0, 0, 0 > }
    finish{ diffuse 0.8 ambient 0.1 specular 0.5 roughness 0.005 }
  }

#declare tx_espelho =
  texture{
    pigment{ color rgb < 1.00, 0.85, 0.30 > }
    finish{ diffuse 0.2 reflection 0.7*< 1.00, 0.85, 0.30 > ambient 0.1 }
  }

#declare tx_asa =
  texture{
    pigment{ color rgb < 0.9, 1, 0.9 > }
    finish{ diffuse 0.8 ambient 0.1 specular 0.5 roughness 0.005 }
  }

#declare tx_vermelho =
  texture{
    pigment{ color rgb < 0.75, 0.25, 0.05 > }
    finish{ diffuse 0.9 ambient 0.1 }
  }

#declare tx_xadrez =
  texture{
    pigment{ checker color rgb < 0.10, 0.32, 0.60 >, color rgb < 1.00, 0.97, 0.90 > }
    finish{ diffuse 0.9 ambient 0.1 }
    scale 2.0
  }

#declare raio = 2.000;

#declare chao =
  box{ <-20,-20,-1>, <+20,+20,0> }

#declare base1 =
  cylinder{
    < 0, 0, 0 >
    < 0, 0, 8 >
    6
    texture{ tx_vermelho }
  }

#declare chassis1 =
  box {
    < 0, 0, 0 >
    < 6, 4, 2 >
    texture{ tx_carro }
  }

#declare chassis2 =
  box {
    < 1.5, 0, 2 >
    < 4.5, 4, 3.5 >
    texture{ tx_carro }
  }

#declare farol =
  sphere {
    < 6, 0.4, 1.6 >
    0.4
  }

#macro articulacao()
  union{
    sphere {
      < 0, 0, 0 >
      0.3
      texture{ Chrome_Texture }
    }
  }
#end

#macro pe()
  union{
    cylinder {
      < 0.2, 0, 0 >
      < 1.2, 0, 0 >
      0.3
      texture{ tx_asa }
    }
  }
#end

#macro anteperna(alfa)
  union{
    cylinder {
      < 0, 0, 0.2 >
      < 0, 0, 3.2 >
      0.3
      texture{ tx_asa }
    }
    object{ pe() rotate alfa*y }
    object{ articulacao() }
  }
#end

#macro perna(alfa, beta)
  union{
    cylinder {
      < 0, 0, 0.2 >
      < 0, 0, 4.2 >
      0.3
      texture{ tx_asa }
    }
    object{ anteperna(alfa) translate -3.4*z rotate -beta*y}
    object{ articulacao() }
  }
#end

#macro perna_completa(alfa, beta, gama)
  union{
    object{ articulacao() }
    object{ perna(alfa, beta) translate -4.4*z rotate gama*y}
  }
#end

#macro carro(alfa, beta, gama)
  union{
    union{
      object{ chassis1 }
      object{ chassis2 }
      object{ farol texture{ tx_espelho } }
      object{ farol texture{ tx_espelho } translate < 0, 3.2, 0 > }
      object{ farol texture{ tx_vermelho } translate < -6, 0, 0 > }
      object{ farol texture{ tx_vermelho } translate < -6, 3.2, 0 > }
    }
    object{ perna_completa(alfa, beta, gama) translate < 3, 1, 0 > }
    object{ perna_completa(alfa, beta, gama) translate < 3, 3, 0 > }

  }
#end

#macro interpolata(ta, va, tb, vb, tt)
  #local s = (tt-ta)/(tb-ta);
  ((1-s)*va+s*vb)
#end

#macro armacao(fase)
  union{
    #declare alfa0 = 30;
    #declare beta0 = 60;
    #declare gama0 = 30;
    #declare pcar0 = 0;

    #declare alfa1 = 30;
    #declare beta1 = 80;
    #declare gama1 = 50;
    #declare pcar1 = -1;

    #declare alfa2 = 30;
    #declare beta2 = 0;
    #declare gama2 = 0;
    #declare pcar2 = 2;

    #declare fase0 = 0.000;
    #declare fase1 = 0.500;
    #declare fase2 = 1.000;
    #if((fase >= fase0) & (fase <= fase1))
      #declare alfa = interpolata(fase0, alfa0, fase1, alfa1, fase);
      #declare beta = interpolata(fase0, beta0, fase1, beta1, fase);
      #declare gama = interpolata(fase0, gama0, fase1, gama1, fase);
      #declare pcar = interpolata(fase0, pcar0, fase1, pcar1, fase);
    #end
    #if((fase >= fase1) & (fase <= fase2))
      #declare alfa = interpolata(fase1, alfa1, fase2, alfa2, fase);
      #declare beta = interpolata(fase1, beta1, fase2, beta2, fase);
      #declare gama = interpolata(fase1, gama1, fase2, gama2, fase);
      #declare pcar = interpolata(fase1, pcar1, fase2, pcar2, fase);
    #end
        object{ carro(alfa, beta, gama) translate z*pcar}
  }
#end

#macro armacao_geral(p, fase)
  union{
    object{ armacao(fase) translate p }
  }
#end

#macro voo(h, fase)
  union{
    #declare alfa2 = 30;
    #declare beta2 = 0;
    #declare gama2 = 0;
    #declare pcar2 = 2;

    #declare alfa3 = 30;
    #declare beta3 = 0;
    #declare gama3 = 0;
    #declare pcar3 = h;

    #declare alfa4 = 30;
    #declare beta4 = 60;
    #declare gama4 = 30;
    #declare pcar4 = 0;

    #declare fase2 = 0.000;
    #declare fase3 = 0.500;
    #declare fase4 = 1.000;

    #if((fase >= fase2) & (fase <= fase3))
      #declare alfa = interpolata(fase2, alfa2, fase3, alfa3, fase);
      #declare beta = interpolata(fase2, beta2, fase3, beta3, fase);
      #declare gama = interpolata(fase2, gama2, fase3, gama3, fase);
      #declare pcar = interpolata(fase2, pcar2, fase3, pcar3, fase);
    #end
    #if((fase >= fase3) & (fase <= fase4))
      #declare alfa = interpolata(fase3, alfa3, fase4, alfa4, fase);
      #declare beta = interpolata(fase3, beta3, fase4, beta4, fase);
      #declare gama = interpolata(fase3, gama3, fase4, gama4, fase);
      #declare pcar = interpolata(fase3, pcar3, fase4, pcar4, fase);
    #end

    object{ carro(alfa, beta, gama) translate z*pcar}
  }
#end

#macro voo_geral(h, p, q, fase)
  union{
    #local r = interpolata(0, p, 1, q, fase);
    object{ voo(h, fase) translate r}
  }
#end

#macro quadro(tt)
  union{

    #local t0 = 0.0000;
    #local t1 = 0.1500;
    #local t2 = 0.3000;
    #local t3 = 0.4500;
    #local t4 = 0.6000;
    #local t5 = 0.7500;
    #local t6 = 1.0000;

    #if((tt >= t0) & (tt <= t1))
      #local fase = interpolata(t0, 0, t1, 1, tt);
      object{ armacao_geral(< 2, 2, 0 >, fase) }
    #end
    #if((tt >= t1) & (tt <= t2))
      #local fase = interpolata(t1, 0, t2, 1, tt);
      object{ voo_geral(10, < 2, 2, 0>, < 42, 2, 0 >, fase) }
    #end

    #if((tt >= t2) & (tt <= t3))
      #local fase = interpolata(t2, 0, t3, 1, tt);
      object{ armacao_geral(< 42, 2, 0 >, fase) }
    #end
    #if((tt >= t3) & (tt <= t4))
      #local fase = interpolata(t3, 0, t4, 1, tt);
      object{ voo_geral(10, < 42, 2, 0>, < 22, 36, 0 >, fase) }
    #end

    #if((tt >= t4) & (tt <= t5))
      #local fase = interpolata(t4, 0, t5, 1, tt);
      object{ armacao_geral(< 22, 36, 0 >, fase) }
    #end
    #if((tt >= t5) & (tt <= t6))
      #local fase = interpolata(t5, 0, t6, 1, tt);
      object{ voo_geral(10, < 22, 36, 0>, < 2, 2, 0 >, fase) }
    #end

  }

#end

#include "eixos.inc"

union{

  object{ base1 translate < 2, 2, -15 >}
  object{ base1 translate < 42, 2, -15 >}
  object{ base1 translate < 22, 36, -15 >}

  object{ quadro(clock) }
}

#include "camlight.inc"
#declare centro_cena = < 0.00, 0.00, 1.00 >;
#declare raio_cena = 70.0;
#declare dir_camera = < 10.00, 15.00, 4.00 >;
#declare dist_camera = 160.0;
#declare intens_luz = 1.00;
camlight(centro_cena, raio_cena, dir_camera, dist_camera , z, intens_luz)