// LAB 05 - O Trem da Alegria
// ======================================================================
// CÂMERA 

camera {
  location  <  -25.00, -10.00, 6.00 >  // Posição do observador.
  right     -1.00*x                // Largura RELATIVA da imagem.
  up        0.50*y                 // Altura RELATIVA da imagem.      
  sky       z                      // Qual direção é "para cima"?
  look_at   <  60.00, 25.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.
} 

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

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


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

background{ color rgb < 0.8, 0.85, 0.9 > }

#include "colors.inc"

#declare tinta_Azul = 
  texture {
    pigment { color rgb < 0.30, 0.00, 1.00 > }
    finish { diffuse 0.5 specular 0.5 roughness 0.005 ambient 0.1 }
  }

#declare tinta_AzulClaro = 
  texture {
    pigment { color rgb < 0.00, 1.00, 1.50 > }
    finish { diffuse 0.5 specular 0.5 roughness 0.005 ambient 0.1 }
  }
  
#declare tinta_Verde = 
  texture {
    pigment { color rgb < 0.00, 1.00, 0.50 > }
    finish { diffuse 0.5 specular 0.5 roughness 0.005 ambient 0.1 }
  }

#declare tinta_VerdeClaro = 
  texture {
    pigment { color rgb < 0.00, 1.50, 1.00 > }
    finish { diffuse 0.5 specular 0.5 roughness 0.005 ambient 0.1 }
  }

#declare tinta_Vermelha = 
  texture {
    pigment { color rgb < 1.00, 0.30, 0.00 > }
    finish { diffuse 0.5 specular 0.5 roughness 0.005 ambient 0.1 }
  }

#declare eixos =
   union {
      cylinder {
        <-100,0,0>,
	<100,0,0>,
	0.3
	pigment {Blue}
	}
       cylinder {
        <0,-100,0>,
	<0,100,0>,
	0.3
	pigment {Red}
	}
      cylinder {
        <0,0,-100>,
	<0,0,100>,
	0.3
	pigment {Green}
	}
}

#declare tempo = clock;
#if (tempo < 0.2)
  #declare posicao = 100 - 500*tempo*tempo;
#else
  #if (tempo < 0.8)
    #declare posicao =	100 - 100 * tempo;
  #else
    #declare posicao = 500 * (1-tempo) * (1-tempo);
  #end
#end


#declare j=0;
#declare g = seed(12346);

#declare cabine =
	 difference {
		    box
		    {
			<posicao+0,0,-0.1>,
			<posicao+2.5,3,4>
		    }
		    box
		    {
			<posicao-1,-1,2.5>,
			<posicao+1.1,4,3.5>
		    }
		    texture {tinta_VerdeClaro}
	 }

#declare engate =
	 cylinder {
		  <posicao+0,0,0>,
		  <posicao+1.5,0,0>,
		  0.2
		  pigment {Pink}
	 }

	 
#declare corpo_locomotiva =
 	 difference {
			    box
		     		{
				<posicao+0,0,0>,
				<posicao+13.5,3,3>
				}
			    box {
			        <0,-1,0>,
				<10,4,10>
				rotate <0,-60,0>
				translate <posicao,0,0>
				}
	 texture {tinta_VerdeClaro }
	 
	 }

#declare chamine =
	 difference {
		    cylinder {
			     <posicao+0,0,-0.1>,
			     <posicao+0,0,5>,
			     1.5
			     }
		    cylinder {
			     <posicao+0,0,-0.2>,
			     <posicao+0,0,5.1>,
			     1
			     }
		    texture {tinta_VerdeClaro }
		    }

#declare roda =
	 cylinder
		{
			<posicao+0,0,0>,
			<posicao+0,0.3,0>,
			1.25
			texture {tinta_Vermelha}
		}
#declare eixo =
	 union {
	       object {roda}
	       object {roda translate <0,2.7,0>}
	       cylinder {
			<posicao+0,0.15,0>,
			<posicao+0,2.85,0>,
			0.2
			pigment {Black}
			}
		}				    		 
	 
#declare locomotiva =

	 union{
		object {corpo_locomotiva}
		object {cabine translate <3,0,3>}
		object {chamine translate <8,1.5,3>}
		object {chamine scale <1,1,1.2> translate <12,1.5,3>}

		#declare i = 1;
		#while (i < 5)
		       object {eixo translate <0.5 + 3*i,0,-1.25>}
		#declare i = i + 1;
		#end
	 }

#declare vagao =
		union {
		      difference
		      {
		      
			box
				{
				<posicao+0.5,0,0>,
				<posicao+11.5,3,5>
				texture {tinta_VerdeClaro}
				}
		        box   {
			      <posicao+0.7,0.2,0.2>,
			      <posicao+11.3,2.8,4.8>
			      texture {tinta_VerdeClaro}
			      }
			#declare i = 1;
			#while(i<4)
			
			 text {ttf "verdanab.ttf" "$" 5,0
			         rotate <90,0,0> scale <2,5,2> translate <posicao+0.25 + 2.5 *i,2,2> texture {tinta_VerdeClaro} }
		       	text {ttf "verdanab.ttf" "$" 3,0
			         rotate <-90,0,0> scale <2,5,2> translate <posicao+0.25 + 2.5 *i,1,3> texture {tinta_VerdeClaro} }
			#declare i = i + 1;
			#end
		       }
		       object {engate translate <-0.9,1.5,0.5>}
		       #declare i = 0;
		       #while (i < 4)
		           object {eixo translate <0.5 + 1.25 + 3*i,0,-1.25> }
			   #declare i = i + 1;
		       #end

		       translate <0.9,0,0> //correçao pra nao ter que refazer as coordenadas em x
		       }


#declare trilhos =
cylinder {
        <-500,0,0>,
	<500,0,0>,
	0.2
	pigment {Black}
	}


#declare trem =
	 union {
	       object {locomotiva}

	        #declare nvag = 5 + 3 * rand(g);
	       #declare i = 0;
	       #while (i < nvag)
	       object {vagao translate <13.49 + i * 12.29 ,0,0>}
	       #declare i = i + 1;
	       #end
	       object { trilhos translate <0,-1,-0.7>}
	       object { trilhos translate <0,2,-0.7> }
	 }
		       
object { trem }
//object { eixos }

plane { z, -1
  texture {
    pigment { wood }
    finish { ambient 0.1 diffuse 0.9 }
    scale 4.0
    }
}