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, A1, A2, A3)
  #local corpo = box {
    <A1, A2, A3> , <A1+2, A2+4, A3+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> + <A1, A2, A3> }
  #local perna_direita = object {braco(D14, D15) rotate <D11, D12, D13> translate <0,  4, 0> + <A1, A2, A3> }
  #local braco_esquerdo = object {braco(E24, E25) rotate <E21, E22, E23> translate <2, 0, 6> + <A1, A2, A3> }
  #local braco_direito = object {braco(D24, D25) rotate <D21, D22, D23> translate <2, 4, 6> + <A1, A2, A3> }
  #local pesco = object {pescoco(P1, P2, P3, P4) rotate <P5, 0, P6> translate <1, 2, 6> + <A1, A2, A3> }

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

  }
#end

// #declare chao = box{ <-200,-200,0>, <+200,+200,0> }

// union{
//   object {chao }
// }


// P: (qED, qFT, qR, J, T)
// B: (Oaf, Ocb, Or, C, P)
// C: (Ped, Pcb, Cgl, Cge, Ted, Tcb)
// A: (X, Y, Z)

// 0       PE            BE              PD            BD              C
//robo (0,180,0,0,0,   160,0,0,0,0,    0,180,0,0,0,    -160,0,0,0,0,    0,0,0,0,0,0,   0,0,0)

//  1      PE            BE              PD            BD              C
//robo (0,145,0,45,0,   160,0,0,0,0,    0,145,0,45,0,    -160,0,0,0,0,    0,0,0,0,0,0,   0,0,-0.7)

// 2       PE                BE                PD                BD              C
//robo (45,180,0,0,0,   180,-45,-90,45,0,    45,180,0,0,0,    -180,45,-90,-45,0,    0,0,0,0,0,0,   0,0,1)

// 3       PE                BE                PD                BD              C
//robo (45,180,0,0,0,   180,-90,-90,45,0,    45,180,0,0,0,    -180,90,-90,-45,0,    0,0,0,0,0,0,   0,0,1)

// 4       PE                BE                PD                BD              C
// robo (45,180,0,0,0,   180,-135,-90,0,0,    -45,180,0,0,0,    -180,135,-90,0,0,    0,0,0,0,0,0,   0,0,0)

//  5      PE                BE                PD                BD              C
//robo (45,180,0,0,0,   180,-90,-90,45,0,    45,180,0,0,0,    -180,90,-90,-45,0,    0,0,0,0,0,0,   0,0,1)

// 6       PE                BE                PD                BD              C
//robo (45,180,0,0,0,   180,-45,-90,45,0,    45,180,0,0,0,    -180,45,-90,-45,0,    0,0,0,0,0,0,   0,0,1)

//  7      PE            BE              PD            BD              C
//robo (0,145,0,45,0,   160,0,0,0,0,    0,145,0,45,0,    -160,0,0,0,0,    0,0,0,0,0,0,   0,0,-0.7)

//  8      PE            BE              PD            BD              C
//robo (0,180,0,0,0,   160,0,0,0,0,    0,180,0,0,0,    -160,0,0,0,0,    0,0,0,0,0,0,   0,0,0)


#macro cena(tt)
  robo (45*(2+cos(tt*2*pi + pi) - abs(cos(tt*2*pi + pi)))/2, 180-35*(2+cos(tt*3*pi + pi*5/2) - abs(cos(tt*3*pi + pi*5/2)))/2,0,45*(2+cos(tt*3*pi + pi*5/2) - abs(cos(tt*3*pi + pi*5/2)))/2,0,       160 + 20*(2+cos(tt*2*pi + pi) - abs(cos(tt*2*pi + pi)))/2,-135*(2+cos(tt*3*pi + pi*5/2) - abs(cos(tt*2*pi + pi)))/2,0,0,0,    -45*(2+cos(tt*2*pi + pi) - abs(cos(tt*2*pi + pi)))/2,180-35*(2+cos(tt*3*pi + pi*5/2) - abs(cos(tt*3*pi + pi*5/2)))/2,0,45*(2+cos(tt*3*pi + pi*5/2) - abs(cos(tt*3*pi + pi*5/2)))/2,0,    -160 + -20*(2+cos(tt*2*pi + pi) - abs(cos(tt*2*pi + pi)))/2,-135*(2+cos(tt*3*pi + pi*5/2) - abs(cos(tt*2*pi + pi)))/2,0,0,0,    0,0,0,0,0,0,   0,0,0)
#end

object{
  cena(clock)
}


#include "camlight.inc"
#declare centro_cena = < 0.00, 0.00, 0.00 >;
#declare raio_cena = 20.0;
#declare dir_camera = < 2.00, 1.00, 0.00 >;
#declare dist_camera = 5*raio_cena;
#declare intens_luz = 1.20;
camlight(centro_cena, raio_cena, dir_camera, dist_camera , z, intens_luz)