// Exemplo de arquivo de descricao de cena para POV-ray
// Last edited on 2003-09-04 15:25:26 by stolfi

// ======================================================================
// CÂMERA 

# include "textures.inc"

camera {
  location  <  30.00, 0.00, 10.00 >  // Posição do observador.
  right     -1.00*x                // Largura RELATIVA da imagem.
  up        0.5*y                 // Altura RELATIVA da imagem.      
  sky       z                      // Qual direção é "para cima"?
  look_at   <  0.00, 0.00, 0.00 >  // Para onde a câmera está apontando.
} 
// Nota: os parâmetros "right" e "up" devem ter a mesma proporção
// que os parâmetros ${WIDTH} e ${HEIGHT} no Makefile.

// ======================================================================
// FONTES DE LUZ

light_source {
  10 * < +50.0, +30.0, +50.0 >              // Posição da lâmpada.
  color rgb 1.2 * < 1.00, 1.00, 1.00 >   // Intensidade e corda luz.
} 

light_source {
  10 * < +50.0, -10.0, +10.0 >             // Posição da lâmpada.
  color rgb 0.8 * < 1.00, 1.00, 1.00 >   // Intensidade e corda luz.
} 

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

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

#declare raio = 2.000;

#declare tinta_A = 
  texture {
    pigment { color rgb < 0.10, 0.80, 1.00 > }
    finish { diffuse 0.5 specular 0.5 roughness 0.005 ambient 0.1 }
  }

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

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


# declare cor_vidro =  < 0,0,0.5>;
# declare tx_vidro =
   texture {
      pigment {rgb cor_vidro}
      finish {
          ambient 0.05 diffuse 0.55
	  reflection cor_vidro
          specular 0.20 roughness 0.05
	}
}


  

# declare gerador = seed(123456);


# declare vagao = 
        
      union{   	
                # declare r=0;
   	        # while (r<4)
                  union{
                  box {<2.5,0,0.5>,<0,0.5,2> texture { tinta_B }}
                  box {<0,0.2,0.5>,<-0.5,0.3,0.7> texture {cor_roda }}
                  cylinder {<0.30,-0.02,0.25 >, <0.30,0.52,0.25 >, 0.25 texture {cor_roda}  translate <0.6*r,0,0> }}                  # declare r=r+1; 
                #end
  
   }


# declare locomotiva =

  union{
   difference{
         box {<2.5,-0.2,0.5>,<0,0.7,2.5> texture { tinta_B }} // corpo
         
         box {<-0.1,-0.3,1.5>,<1,0.8,2.6> texture { tinta_B }} // corte  

   }
        box {<1.2,-0.21,1.5>,<2,0.71,2.2> texture {tx_vidro } } // janela
        cylinder {<0.30,-0.22,0.25 >, <0.30,0.82,0.25 >, 0.25 texture {cor_roda}   }      
        cylinder {<0.30,-0.22,0.25 >, <0.30,0.82,0.25 >, 0.25 texture {cor_roda}  translate <1.5,0,0> }      
        translate <-1.25,-0.25+9.5,0> 
       
}



# declare trem =
   union {
        object {locomotiva rotate 17*z }
  	# declare j=0;
   	# while (j<3)
      		# declare i=0;
      		#while (i<5)
        	union{
          	    union {
                     	object { vagao }
          		# if (rand(gerador) > 0.5)
      		   		box {<0.1,-0.02,1.1>,<0.4,0.52,1.4> texture {tx_vidro } translate <0.5*i,0,0>}
          		# else
                        	cylinder {<0.25,-0.02,1.25 >, <0.25,0.52,1.25 >, 0.2 texture {tx_vidro} translate <0.5*i,0,0>} 
          		#end 
                   // rotate -15*z*j
                    }
          	translate <-1.25,-0.25+9.5,0>  rotate -18*z*j
        	} 
        	# declare i=i+1;
       		#end
       	# declare j=j+1;
    	#end
 
}


#declare trilho = 
  difference {
     lathe {  linear_spline 
    2,< 9, 0 >,
    < 10, 0.3 >
   
   texture {  tx_vidro }
    rotate 90*x
  }

  lathe {  linear_spline 
    2,< 9.1, 0 >,
    < 9.99, 0.3 >
      texture {  tx_vidro }
    rotate 90*x
  }
}




  


plane{z,-0.1
    texture{ Jade}
}

#declare eixo = 
  union {
  	cylinder {
  		 <0,0,0 >,
   		 <1000,0,0 >,
    		 0.05
    		texture { tinta_B }
  	}
	cylinder {
                 <0,0,0 >,
   		 <0,1000,0>,
  		 0.05
    		texture { tinta_B }
  	}
	cylinder {
                 <0,0,0 >,
   		 <0,0,1000 >,
                 0.05
    		texture { tinta_B }
  	}



}

# declare estacao = union{ box {<0,0,0>,<3,3,3> texture { tinta_A }}}
  


#declare tempo=clock;
#declare h=0.2;
#declare D=360;
#declare A=D/(2*h*(1-h));
#declare B=-A*h*h;
#declare C=2*A*h;


#if (tempo<0.2)
     #declare pos =  A*clock*clock;
#else 
    #if (tempo<0.8)
	#declare pos =  B+C*clock;
    #else 
	#declare pos =  (D-A*(1-clock)*(1-clock));
    #end
 #end






// Aqui está a cena, finalmente:


  	union {
 	//	object { eixo }
                object {trilho}
               // object {locomotiva}
                object {estacao translate <0,12,0>}
       union { 
                object { trem } rotate z*pos
             //   object {estacao}

        }     
                
}