// Last edited on 2023-12-24 15:16:23 by stolfi
background{ color rgb < 1, 1, 1 > }

#declare steel_1 = // aço
  texture{
    pigment{ color rgb < 0.70, 0.70, 0.70 > }
    finish{ diffuse 0.5 ambient 0.1 brilliance 1 reflection 0.1 specular 0.2 roughness 0.5}
  }

#declare tx_plastico = 
  texture{
    pigment{ color rgb < 0.10, 0.80, 1.00 > }
    finish{ diffuse 0.8 ambient 0.1 specular 0.5 roughness 0.005 }
  }
#declare tx_2 = 
  texture{
    pigment{ color rgb < 0.30, 0.30, 0.30 > }
    finish{ diffuse 0.5 ambient 0.1 brilliance 1 reflection 0.15 specular 0.2 roughness 0.5}
  }

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

#declare tx_4 = 
  texture{
    pigment{ color rgb < 0.25, 0.59, 0.04 > }
    finish{ diffuse 0.3 ambient 0.1 specular 0.5 roughness 1 }
  }



#macro punho ()
  #local tronco = cone {
    <0, 0, 0>, 0 // <x, y, z>, center & radius of one end
    <0, 0, 1>, 0.3 // <x, y, z>, center & radius of the other end
  }
  union {
    object {tronco texture {tx_2}}
  }
#end

#macro antebraco (c)
  #local tronco = cylinder {
    <0, 0, 0>, <0, 0, 1.5>, 0.4 // center of one end, center of other end, radius
  }
  #local pun = object{punho()}
  union {
    object{tronco texture {tx_xadrez}}
    object{pun rotate <0, c, 0> translate <0, 0, 1.5>}
  }
#end 

#macro braco (b, c)
  #local tronco = cylinder {
    <0, 0, 0>, <0, 0, 2>, 0.4 // center of one end, center of other end, radius
  }
  #local ante = object{antebraco (c)}
  union {
    object{tronco texture {tx_4}}
    object{ante rotate <0, b, 0> translate <0, 0, 2>}
  }
#end


#macro cabeca ()
  #local cabe = sphere {
    <0, 0, 0>, 1 // <x, y, z>, radius
    
  }
  union {
    object{cabe texture {tx_xadrez}}
  }
#end 


#macro subpescoco (c)
  #local tronco = cylinder {
    <0, 0, 0>, <0, 0, 0.6>, 0.4 // center of one end, center of other end, radius
  }

  #local cab = object{cabeca()}
  union {
    object{tronco texture {tx_2}}
    object{cab rotate <0, c, 0> translate <0, 0, 1.6>}
  }
#end 

#macro pescoco (b1, b2, b3, c)
  #local tronco = cylinder {
    <0, 0, 0>, <0, 0, 1>, 0.4 // center of one end, center of other end, radius
  }

  #local sub = object{subpescoco (c)}
  union {
    object{tronco texture {tx_4}}
    object{sub rotate <b1, b2, b3> translate <0, 0, 1>}
  }

#end 

#macro robo (E11, E12, E13, E14, E15, E21, E22, E23, E24, E25, D11, D12, D13, D14, D15, D21, D22, D23, D24, D25,P1, P2, P3, P4, P5, P6)
  #local corpo = box {
    <0, 0, 0>, <2, 4, 6> // <x, y, z> near lower left corner, <x, y, z> far upper right corner
    texture {tx_plastico}
    
  }
  #local perna_esquerda = object {braco(E14, E15) rotate <E11, E12, E13> translate <0, 0, 0> }
  #local perna_direita = object {braco(D14, D15) rotate <D11, D12, D13> translate <0,  4, 0> }
  #local braco_esquerdo = object {braco(E24, E25) rotate <E21, E22, E23> translate <2, 0, 6> }
  #local braco_direito = object {braco(D24, D25) rotate <D21, D22, D23> translate <2, 4, 6> }
  #local pesco = object {pescoco(P1, P2, P3, P4) rotate <P5, 0, P6> translate <1, 2, 6>}

  union {
    object {corpo}
    object {perna_esquerda}
    object {perna_direita}
    object {braco_esquerdo}
    object {braco_direito}
    object {pesco}

  }
#end

#declare DX = 6;
#declare DY = 7;
#declare DZ = 7;

object { 
  robo ( 
     10, 225,   0,  20,  5,   
     45, 135,  20, -90, 45,    
     10, 135,   0,  20, 50,    
    -45, 225,  20, -90, 45,    
     20,   0,   0,  90, 45, 90
  )
  translate -DX*x
}

object { 
  robo ( 
    150, -90,   0, -90,-40,   
     45,  35,  20, -90, 45,    
   -150, -90,   0, -60,-40,    
    -45,-185,  20, -90, 45,    
    +50,   0,   0,  90,-45,  90
  )
  translate +DX*x
}

#declare cmin = < -2*DX+0, -DY+3, -DZ+2 >;
#declare cmax = < +2*DX+1, +DY+1, +DZ+3 >;

#include "gaiola.inc"
// object{ gaiola(cmin,cmax) }

#declare centro_cena = (cmin + cmax)/2;
#declare raio_cena = 0.45*vlength(cmax-cmin);
#declare dist_camera = 7*raio_cena;

#include "camlight.inc"
#declare dir_camera = < 7, 5, 3 >;
#declare intens_luz = 1.20;
camlight(centro_cena, raio_cena, dir_camera, dist_camera , z, intens_luz)