#include "colors.inc"
// ======================================================================
// CÂMERA 

camera {
  location  <0.0, 0.5, -350.0>
  right     -1.0*x                // Largura RELATIVA da imagem.
  up        0.75*y                 // Altura RELATIVA da imagem.     
  direction 1.5*z
  look_at   <0, 0, 0>
  rotate 10*x 
  //rotate -90*y
}
// 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 {
  //<0, 0, 0>    
  //color rgb <1, 1, 1>
  //translate <30, 20, -50>
  //rotate -30*y
//}

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.
  rotate 60*y
} 

//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 

#declare fonte=seed(314159);

sky_sphere {
  pigment {
    gradient y
    color_map {
      [0.0 rgb <0.6,0.7,1.0>]
      [0.7 rgb <0.0,0.1,0.8>]
    }
  }
}

plane {
  y, -1
  pigment { color rgb <0.7,0.5,0.3> }
}

#declare tx_espelho =
  texture{
    pigment {Gray70}
    finish{
      ambient 0.05 diffuse 0.05
      reflection{
         Silver
         metallic
       }
      specular 0.20 roughness 0.05
    }
  }

#declare tx_pedras =
  texture{
     finish {
         ambient 0.1 diffuse 0.1 reflection 0.25
         specular 1 roughness 0.001
     }
     pigment {color rgb <0, 1, 1>}
  }


declare box_janela = 
     box{
          <-15, 11.5, -16.25> <-9, 13.6, -16.25001>
          texture{tx_espelho}
          
         }

declare cilindro_janela = 
  cylinder{
            <-14, 11.0, -16.25>,
            <-14, 11.0, -16.25001>,
            1.7
            texture{tx_espelho}
          
          } 

#declare vagao =
   union{
     #declare r = 1*rand(fonte);
     #declare g = 1*rand(fonte);
     #declare b = 1*rand(fonte);	
     box {
       <-16.25,0,-16.25> <16.25, 15, 6.25>
	pigment {color rgb <r, g, b>}
        translate<0,2.5,0> 
     }
     #declare i =0;
     #while (i<4)
       cylinder{
         <-12.75, 2.5, -16.25>,
         <-12.75, 2.5, -17.5>,
         2.7
         translate<i*8.5, 0, 0>
       }
       //TODO: tirar esse cilindor debaixo e dar rotate 180 usando o de cima duas vezes
       cylinder{
         <-12.75, 2.5, 16.251>,
         <-12.75, 2.5, 15.5>,
         2.7
         translate<i*8.5, 0, 0>
       }
       #declare i = i +1;
     #end
     #declare i=0;
     #declare flag = 0;
     #while (i<5)
       #if (flag = 0)
        object{
           box_janela
           translate<i*6,2,0>
        }
        object{
           box_janela
           translate<i*6,2,0>
           rotate 180*y
        } 
        #declare flag= 1;
       #else
        object{
           cilindro_janela
           translate<i*7,-1,0>
        }
        object{
           cilindro_janela
           translate<i*7,-1,0>
           rotate 180*y
        }
        #declare flag = 0;
      #end
      #declare i = i +1;
    #end    
  }

declare ligacao =
  box{
     0 <6, 1.5, 1.5>
  }

declare trilho =
  union{
    torus {
      100, 5.5
      pigment{Gray70}
      translate<0, 0, 9.5>
    }
    cylinder{
     0, <-100, 0, 0>,
     7.5
     pigment{Gray70}
    }  
 } 

union{
  
  #declare r = 10*rand(fonte);
  #declare i = 0;  
  #while (i<r)
    object{
     vagao
     translate<38*i, 0, 0>
    }      
    #if (i < (r-1))
     object {
      ligacao
      translate<38*i+16.26, 3, 0>
     }
   #end
   #declare i = i+1;
 #end
 object {trilho}
  
}