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

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

#declare tx_perna =
  texture{
    pigment{ color rgb < 139/255, 69/255, 19/255 > }
    finish{ diffuse 0.8 ambient 0.5 specular 0.5 roughness 0.005 }
  }

#declare tx_pele =
  texture{
    pigment{ color rgb < 210/255, 105/255, 30/255 > }
    finish{ diffuse 0.8 ambient 0.5 specular 0.5 roughness 0.005 }
  }

#declare tx_folha =
  texture{
    pigment{ color rgb < 0.1, 1, 0.1 > }
    finish{ diffuse 0.8 ambient 0.5 specular 0.5 roughness 0.005 }
  }

#include "math.inc"

#macro boneco(Be, Bd, ABe, ABd, Cxe, Cxd, Ce, Cd, Pe, Pd)
union {
  object{ corpo() }
  object{ braco(ABe*y) //braco esquerdo
          rotate Be*y
          translate <-6,0,8>
          }

  object{ braco(-ABd*y) //braco direito
          rotate -Bd*y
          translate <6,0,8>
          }
  object{ coxa(Ce*x, Pe*x)
          rotate Cxe*x
          translate <-4,0,0>
          }
  object{ coxa(Cd*x, Pd*x)
          rotate Cxd*x
          translate <4,0,0>
          }
}
#end

#macro corpo()
union{
  cylinder{ <0,0,10>, <0,0,11>, 1 //pescoco
          texture{tx_pele}
        }
  sphere { <0,0,14>, 3 //cabeca
          texture{tx_pele}
        }
  cylinder {<0,0,14>, <0,7,14>, 0.35 //nariz
              texture{tx_pele}
              }
  cylinder {<-1,2,15>, <-1,2.8,15>, 0.3} //olho1
  cylinder {<1,2,15>, <1,2.8,15>, 0.3} //olho2
  cylinder{ <0,0,0>, <0,0,10>, 5 //corpo
          texture{tx_pele}
          }
  sphere { <6,0,9>, 2 //ombro1
            texture{tx_pele}
            }
  sphere { <-6,0,9>, 2 //ombro2
            texture{tx_pele}
            }
  cone { <-2,0,16>, 1, <-3.5,0,17.5>, 0 //orelha1
          texture{tx_pele}
          }
  cone { <2,0,16>, 1, <3.5,0,17.5>, 0 //orelha2
          texture{tx_pele}
          }
}
#end

#macro pe()
box{ <-1.2,4,-1> , <1.2,-1,0> }

#end

#macro canela(RotacaoP)
union {
  cylinder{ <0,0,0>, <0,0,-6>, 1.2
          }
  object{ pe()
          rotate RotacaoP
          translate <0, 0, -6>
          }
}
#end

#macro coxa(RotacaoC, RotacaoP)
union {
  cylinder{ <0,0,0>, <0,0,-7>, 1
          texture{tx_pele}
          }
  object{ canela(RotacaoP)
          rotate RotacaoC
          translate <0, 0, -7>
          }
}
#end

#macro braco(Rotacao)
union {
  cylinder{ <0,0,0>, <0,0,-4>, 1
          texture{tx_pele}
          }
  object{ antebraco()
          rotate Rotacao
          translate <0,0,-4> }
}
#end

#macro antebraco()
union {
  cylinder{ <0,0,0>, <0,0,-5>, 1
          texture{tx_pele}
          }
  sphere { <0,0,-6>, 1
          texture{tx_pele}
          }
}
#end

#declare NQ = 11;
#declare argA = array[NQ] {0, 30, 90, 120, 120, 120, 120, 120, 90, 30, 0}
#declare argB = array[NQ] {0, 30, 90, 120, 120, 120, 120, 120, 90, 30, 0}
#declare argC = array[NQ] {0, 30, 90, 120, 90, 60, 90, 120, 90, 30, 0}
#declare argD = array[NQ] {0, 30, 90, 60, 90, 120, 90, 60, 90, 30, 0}
#declare argE = array[NQ] {0, 0, 0, 30, 60, 90, 90, 70, 90, 30, 0}
#declare argF = array[NQ] {0, -45, -60, -30, 0, 0, 20, 30, 30, 20, 0}
#declare argG = array[NQ] {0, 0, -30, -60, -90, -70, -40, 0, -10, -10, 0}
#declare argH = array[NQ] {0, -30, -45, -60, -90, -90, -40, -20, 0, 0, 0}
#declare argI = array[NQ] {0, -30, -60, -60, -60, -40, -20, -10, 0, 0, 0}
#declare argJ = array[NQ]{0, 0, 0, 0, -30, -60, -30, 0, 20, 10, 0}

#declare tempo= array[NQ] {0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0}

#macro interpola(f0, v0, f1, v1, f)
  #local ss = (f-f0)/(f1-f0);
  #local rr = 1-ss;

  (rr*v0 + ss*v1)
#end

#macro quadro_anterior(fase)
  #local i=0;
  #while(i<NQ-1)
    #if((tempo[i]<=fase) & (tempo[i+1]>=fase))
      #local resp = i;
    #end
    #local i=i+1;
  #end
  resp
#end

#macro dancar(fase)
  #local Qanterior = quadro_anterior(fase);
  #local varA = interpola(tempo[Qanterior], argA[Qanterior], tempo[Qanterior+1], argA[Qanterior+1], fase);
  #local varB = interpola(tempo[Qanterior], argB[Qanterior], tempo[Qanterior+1], argB[Qanterior+1], fase);
  #local varC = interpola(tempo[Qanterior], argC[Qanterior], tempo[Qanterior+1], argC[Qanterior+1], fase);
  #local varD = interpola(tempo[Qanterior], argD[Qanterior], tempo[Qanterior+1], argD[Qanterior+1], fase);
  #local varE = interpola(tempo[Qanterior], argE[Qanterior], tempo[Qanterior+1], argE[Qanterior+1], fase);
  #local varF = interpola(tempo[Qanterior], argF[Qanterior], tempo[Qanterior+1], argF[Qanterior+1], fase);
  #local varG = interpola(tempo[Qanterior], argG[Qanterior], tempo[Qanterior+1], argG[Qanterior+1], fase);
  #local varH = interpola(tempo[Qanterior], argH[Qanterior], tempo[Qanterior+1], argH[Qanterior+1], fase);
  #local varI = interpola(tempo[Qanterior], argI[Qanterior], tempo[Qanterior+1], argI[Qanterior+1], fase);
  #local varJ = interpola(tempo[Qanterior], argJ[Qanterior], tempo[Qanterior+1], argJ[Qanterior+1], fase);

  object {
    boneco(varA,varB,varC,varD,varE,varF,varG,varH,varI,varJ)
  }
#end

#declare raio = 10.000;

#include "eixos.inc"

union{
    object {eixos(15.00) }

    object {dancar(clock)
            translate <10,0,0>
            }
 }

#include "camlight.inc"
#declare centro_cena = < 0.00, 0.00, 6.00 >;
#declare raio_cena = 40.0;
#declare dir_camera = < 5.00, 10.00, 0.00 >;
#declare dist_camera = 35.0;
#declare intens_luz = 1.00;
camlight(centro_cena, raio_cena, dir_camera, dist_camera , z, intens_luz)