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

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

#declare raio = 2.000;

#declare tinta_A =
  texture {
    pigment { color rgb < 0.90, 0.80, 0.60 > }
    finish { diffuse 0.8 specular 0.2 roughness 0.005 ambient 0.1 }
  }

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

#declare tinta_C =
  texture {
    pigment { color rgb < 0.40, 0.80, 1.00 > }
    finish { diffuse 0.8 specular 0.2 roughness 0.005 ambient 0.1 }
  }

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

#declare tinta_Teto =
  texture {
    pigment { color rgb < 0.90, 0.30, 0.30 > }
    finish { diffuse 0.8 specular 0.2 roughness 0.005 ambient 0.1 }
  }

#declare tinta_Cargo =
  texture {
    pigment { color rgb < 0.40, 0.30, 0.50 > }
    finish { diffuse 0.8 specular 0.2 roughness 0.005 ambient 0.1 }
  }

#declare cor_esmeralda = <0.2 0.5 0.4>;
#declare tx_esmeralda =
   texture {
     finish {
      ambient 0.1 diffuse 0.2 reflection 0.04
      specular 1 roughness 0.003
     }
     pigment { color cor_esmeralda filter 1 }
   }

#declare cor_ruby = <0.6 0.4 0.3>;
#declare tx_ruby =
   texture {
     finish {
      ambient 0.1 diffuse 0.2 reflection 0.04
      specular 1 roughness 0.003
     }
     pigment { color cor_ruby filter 1 }
   }

#declare cor_prata = <0.7 0.7 0.8>;
#declare tx_prata =
   texture {
     pigment { rgb cor_prata }
     finish {
       ambient 0.05 diffuse 0.1
       reflection cor_prata
       specular 0.3 roughness 0.7
     }
   }

#declare cor_ouro =  < 1.00, 0.80, 0.10 >;
#declare tx_ouro =
   texture {
     pigment { rgb cor_ouro }
     finish {
       ambient 0.05 diffuse 0.05
       reflection cor_ouro
       specular 0.20 roughness 0.05
     }
   }

#declare base =
    torus {
       3,0.5
       texture { tx_ouro }
     }

#declare roda =
    cylinder {
      <0,-0.1,0>
      <0,+0.1,0>
      0.4
      texture { tx_ouro }
      interior { ior 1.5 }
    }

#declare rodas =
 union {
 #declare i = 0;
 #while (i < 5)
  object { roda translate < -2.5 + 1.2*i, 0, 0 > }
  #declare i = i + 1;
 #end
}

#declare vkernel =
    difference {
     box {
        <-3.5, 1, +2.5>
        <+3.5, -1, -0.3>
        texture { tinta_A }
 }
 box {
  <-3.0, 1.2, +0.3>
  <+3.0, 0.7, -0.4>
  texture { tinta_A }
 }
 box {
  <-3.0, -1.2, +0.3>
  <+3.0, -0.7, -0.4>
  texture { tinta_A }
 }
 box {
  <-3.6, 1.2, +2.51>
  <-3.0, -1.2, 1>
  texture { tinta_A }
 }
 box {
  <+3.6, 1.2, +2.51>
  <+3.0, -1.2, 1>
  texture { tinta_A }
 }
 box {
        <-2.8, 1, +2.51>
        <+2.8, -1, 0.32>
        texture { tinta_A }
 }

 }

#declare teto =
 box {
  <3.7, 1.2, 2.6>
  <-3.7, -1.2, 2.4>
  texture { tinta_Teto }
 }

#declare janela_r =
 cylinder {
  < 0, +1.1, 0>
  < 0, -1.1, 0>
  0.3
  texture { tinta_C }
 }

#declare janela_q =
 box {
  <+0.3, +1.1, +0.3>
  <-0.3, -1.1, -0.3>
  texture { tinta_D }
 }

#declare janelas =
 union {
  #declare gerador = seed(123456);
  #declare i = 0;
  #while(i<6)
   #declare r = 10*rand(gerador);
   #if (r > 5)
    object { janela_r translate < -2.5 + i, 0, 1.8> }
   #else
    object { janela_q translate < -2.5 + i, 0, 1.8> }
   #end
   #declare i = i + 1;
  #end
 }

#declare vagao_sj =
 union {
  object {vkernel}
      object {rodas translate < 0, +1, 0,>}
      object {rodas translate < 0, -1, 0,>}
     object {teto}
 }

#declare vagao_carga =
 union {
  object {vkernel}
      object {rodas translate < 0, +1, 0,>}
      object {rodas translate < 0, -1, 0,>}
 }

#declare vagao_carga_final =
 object { vagao_carga translate < 0, +30, 0>}

#declare vagao_pass =
 difference {
  object { vagao_sj }
  object { janelas }
 }

#declare vagao_pass_final =
 object { vagao_pass translate < 0, +30, 0>}

#declare trem_sem_maquina =
 union {
  #declare i = 0;
  #while (i<13)
   #declare r = 10*rand(gerador);
   #if (r > 5)
    object { vagao_pass_final rotate 18*i*z }
   #else
    object { vagao_carga_final rotate 18*i*z }
   #end
   #declare i = i + 1;
  #end
 }

#declare mkernel =
 difference {
      box {
         <-4.5, 1, +2.5>
         <+4.0, -1, -0.3>
         texture { tinta_A }
  }
  box {
   <-2.5, 1.2, +0.3>
   <+3.5, 0.7, -0.4>
   texture { tinta_A }
  }
  box {
   <-2.5, -1.2, +0.3>
   <+3.5, -0.7, -0.4>
   texture { tinta_A }
  }
  box {
   <-4.6, 1.2, +2.51>
   <-4.2, -1.2, 1>
   texture { tinta_A }
  }
  box {
   <+4.6, 1.2, +2.51>
   <-0.5, -1.2, 0.5>
   texture { tinta_A }
  }
  box {
   <-4.0, 0.9, +2.51>
   <-0.9, -0.9, 1>
   texture { tinta_A }
  }
  box {
   <-3.2, 1.2, 2.3>
   <-2.2, -1.2, 1.3>
   texture { tinta_A }
  }
  }

#declare caldeira =
 union {
  cylinder {
   <3.9, 0, 1.2>
   <-0.5, 0, 1.2>
   0.8
   texture { tinta_A }
  }
  cylinder {
   <2.5, 0, 3.3>
   <2.5, 0, 1.8>
   0.38
   texture { tinta_A }
  }
 }

#declare tetinho =
 box {
  <-0.5, 1.0, 2.7>
  <-4.8, -1.0, 2.4>
  texture { tinta_Teto }
 }

#declare maquina =
 union {
  object {mkernel}
  object {rodas translate < 0.5, +1, -0.1>}
      object {rodas translate < 0.5, -1, -0.1>}
  object {caldeira}
  object {tetinho }
 }

#declare trilho =
   union {
     difference {
 cylinder {
   <0, 0, -0.5>
   <0, 0, -0.7>
   31.3
   texture {tinta_D}
 }
 cylinder {
   <0, 0, -0.49>
   <0, 0, -0.71>
   31
   texture {tinta_D}
 }
      }
 difference {
 cylinder {
   <0, 0, -0.5>
   <0, 0, -0.7>
   29.3
   texture {tinta_D}
 }
 cylinder {
   <0, 0, -0.49>
   <0, 0, -0.71>
   29
   texture {tinta_D}
 }
      }
   }

#declare station =
 union {
    difference {
  box {
   <20,10,10>
   <-20,-10,0>
   texture {tinta_Cargo}
  }
  box {
   <21,0,6>
   <-21,-11,0.01>
   texture {tinta_Cargo}
  }
     }
 }

#declare tt = clock;
   #if (tt<0.20)
 #declare posicao = 1100*tt*tt;
   #else
 #if (tt<0.80)
  #declare posicao = -44+440*tt;
    #else
  #declare posicao = 360-1300*(1-tt)*(1-tt);
 #end
   #end

#declare trem_total=
union {
    object {maquina translate <0, 30, 0> rotate -20*z}
    object { trem_sem_maquina }
}

union {
    object {trem_total rotate -1*posicao*z}
    object {trilho}
    object { station translate <0,33,-0.6>}
}

#include "camlight.inc"
camlight(<0,0,0>,<90.00,20.00,20.00>,1.00,z,1.0)