// Exemplo de arquivo de descricao de cena para POV-ray
// Last edited on 2010-03-04 15:44:01 by stolfi

// ======================================================================
// CORES E TEXTURAS

#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
  }


// ======================================================================
// DESCRIÇÃO DA CENA 

#declare raio = 2.000;

// Partes da cena:

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

#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

/*  
#declare filme = 
  union{
    object{ shuriken }
    object{ asa rotate < abs(sin(2*pi*clock))*90, 0, 70 >  translate <1, -1, 1 > }
    object{ asa rotate < abs(sin(2*pi*clock))*90, 0, -70 >  translate <-1, -1, 1 > }
    translate < sin(2*2*pi*clock)*4, 0, cos(2*2*pi*clock)*4> 
  }
*/

#include "eixos.inc"

// Aqui está a cena, finalmente:

union{
  
  #declare alfa0 = 30;
  #declare beta0 = 60;
  #declare gama0 = 30;
  #declare pcar0 = 0;
  
  #declare alfa1 = 30;
  #declare beta1 = 80;
  #declare gama1 = 50;
  #declare pcar1 = -3;
  
  #declare alfa2 = 30;
  #declare beta2 = 0;
  #declare gama2 = 0;
  #declare pcar2 = 0;
  
  #declare alfa3 = 30;
  #declare beta3 = 0;
  #declare gama3 = 0;
  #declare pcar3 = 3;
  
  #declare alfa4 = 30;
  #declare beta4 = 60;
  #declare gama4 = 30;
  #declare pcar4 = 0;
  
  #declare t0 = 0.000;
  #declare t1 = 0.250;
  #declare t2 = 0.500;
  #declare t3 = 0.750;
  #declare t4 = 1.000;
  
  #if((clock >= t0) & (clock <= t1))
    #declare alfa = interpolata(t0, alfa0, t1, alfa1, clock);
    #declare beta = interpolata(t0, beta0, t1, beta1, clock);
    #declare gama = interpolata(t0, gama0, t1, gama1, clock);
    #declare pcar = interpolata(t0, pcar0, t1, pcar1, clock);
  #end
  #if((clock >= t1) & (clock <= t2))
    #declare alfa = interpolata(t1, alfa1, t2, alfa2, clock);
    #declare beta = interpolata(t1, beta1, t2, beta2, clock);
    #declare gama = interpolata(t1, gama1, t2, gama2, clock);
    #declare pcar = interpolata(t1, pcar1, t2, pcar2, clock);
  #end
  #if((clock >= t2) & (clock <= t3))
    #declare alfa = interpolata(t2, alfa2, t3, alfa3, clock);
    #declare beta = interpolata(t2, beta2, t3, beta3, clock);
    #declare gama = interpolata(t2, gama2, t3, gama3, clock);
    #declare pcar = interpolata(t2, pcar2, t3, pcar3, clock);
  #end
  #if((clock >= t3) & (clock <= t4))
    #declare alfa = interpolata(t3, alfa3, t4, alfa4, clock);
    #declare beta = interpolata(t3, beta3, t4, beta4, clock);
    #declare gama = interpolata(t3, gama3, t4, gama4, clock);
    #declare pcar = interpolata(t3, pcar3, t4, pcar4, clock);
  #end
  
  object{ chao  translate < 0,0,-9 > texture{ tx_xadrez } }
  object{ carro(alfa, beta, gama) translate pcar*z }

}

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