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

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

#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 chao =
  box{ <-20,-20,-1>, <+20,+20,0> }

#include "eixos.inc"

#macro cabeca ()
 sphere{
 < 0,0,3 >, 0.5
    texture{ tx_plastico }
  }
#end

#macro pescoco ()
 cylinder{
 <0,0,2.3>,<0,0,2.5>,0.1
 texture{ tx_plastico }
}
#end

#macro pe ()
 box{  <0,0,0>,<0.6,0.2,0.1>
  texture{ tx_plastico } }
#end

#macro mao ()
 box{  <0,0,0>,<0.2,0.6,0.1>
  texture{ tx_plastico } }
#end

#macro corpo ()
 box{  <0.3,-0.3,1>,<-0.3,0.3,2.3>
  texture{ tx_plastico } }
#end

#macro orelha ()
 cone{
  <0,0,0>,0.2,<0,0,0.2>,0.1
texture{ tx_plastico } }
#end

#macro coxa ()
  cylinder{
  <0,0,0>,<0,0,-0.8>,0.07
  texture{ tx_plastico } }
#end

#macro peinf ()
  cylinder{
  <0,0,0>,<0,0,-0.4>,0.07
  texture{ tx_plastico } }
#end

#macro subperna(a)
  union{
   object{ peinf() }
   object{ pe() rotate<0,a,0> translate<0,-0.09,-0.4>}
   }
#end

#macro perna(a,b)
  union{
  object{ coxa() }
  object{ subperna(a) rotate<0,b,0> translate<0,0,-0.8> }
  }
#end

#macro antebraco()
  cylinder{
  <0,0,0>,<0,0.4,0>,0.07
  texture{ tx_plastico } }
#end

#macro subbraco(a)
  union{
  object{ antebraco() }
  object{ mao() rotate<a,0,0> translate<0,0.4,0>}
  }
#end

#macro muc()
  cylinder{
  <0,0,0>,<0,0.4,0>,0.07
  texture{ tx_plastico } }
#end

#macro braco(a,b)
  union{
  object{ muc() }
  object{ subbraco(b) rotate<a,0,0> translate<0,0.4,0> }
  }
#end

  object{ eixos(3.00) }

#macro boneco(a,b,c,d,e,f,g,h,i,j)
  union{
  object { cabeca() }
  object { pescoco() }
  object { corpo() }
  object { orelha() rotate <-30,0,0> translate <0,0.3,3.4>  }
  object { orelha() rotate <30,0,0> translate <0,-0.3,3.4>  }
  object { perna(a,b) rotate<0,i,0> translate<0,0.2,1> }
  object { perna(c,d) rotate<0,j,0> translate<0,-0.2,1> }
  object { braco(e,f) translate<0,0.3,2> }
  object { braco(g,h) translate<0,0.3,2> scale<1,-1,1> }
  }
#end

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

  (rr*v0 +ss*v1)
#end

#declare NQ = 7;  //num de quadros

#declare argA = array[NQ];
#declare argA[0] = 45;
#declare argA[1] = 15;
#declare argA[2] = -15;
#declare argA[3] = -45;
#declare argA[4] = -15;
#declare argA[5] = 15;
#declare argA[6] = 45;

#declare argA2 = array[NQ];
#declare argA2[0] = 45;
#declare argA2[1] = 15;
#declare argA2[2] = -15;
#declare argA2[3] = -45;
#declare argA2[4] = -15;
#declare argA2[5] = 15;
#declare argA2[6] = 45;

#declare argB = array[NQ];
#declare argB[0] = 75;
#declare argB[1] = 15;
#declare argB[2] = -15;
#declare argB[3] = -75;
#declare argB[4] = -15;
#declare argB[5] = 15;
#declare argB[6] = 75;

#declare argB2 = array[NQ];
#declare argB2[0] = 75;
#declare argB2[1] = 15;
#declare argB2[2] = -15;
#declare argB2[3] = -75;
#declare argB2[4] = -15;
#declare argB2[5] = 15;
#declare argB2[6] = 75;

#declare argC = array[NQ];
#declare argC[0] = -75;
#declare argC[1] = -45;
#declare argC[2] = -15;
#declare argC[3] =   0;
#declare argC[4] = -15;
#declare argC[5] = -45;
#declare argC[6] = -75;

#declare argD = array[NQ];
#declare argD[0] = 75;
#declare argD[1] = 45;
#declare argD[2] = 15;
#declare argD[3] =  0;
#declare argD[4] = 15;
#declare argD[5] = 45;
#declare argD[6] = 75;

#declare tempo = array[NQ];
#declare tempo[0] = 0.0;
#declare tempo[1] = 0.17;
#declare tempo[2] = 0.34;
#declare tempo[3] = 0.50;
#declare tempo[4] = 0.67;
#declare tempo[5] = 0.74;
#declare tempo[6] = 1.0;

#macro quadroanterior(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 boneco_dancando(fase)
  #local q = quadroanterior(fase);

  #local ta = fase;

  #declare Bd1 = interpola(tempo[q],argA[q],tempo[q+1],argA[q+1],ta);
  #declare Bd2 = interpola(tempo[q],argB[q],tempo[q+1],argB[q+1],ta);
  #declare Be1 = interpola(tempo[q],argA2[q],tempo[q+1],argA2[q+1],ta);
  #declare Be2 = interpola(tempo[q],argB2[q],tempo[q+1],argB2[q+1],ta);
  #declare Pd = interpola(tempo[q],argC[q],tempo[q+1],argC[q+1],ta);
  #declare Pe = interpola(tempo[q],argD[q],tempo[q+1],argD[q+1],ta);

  object{ boneco(Pd,0,Pe,0,Be1,Be2,Bd1,Bd2,0,0)}
#end

union{
  boneco_dancando(clock)
}

#include "camlight.inc"
#declare centro_cena = < 1.00, 1.00, 1.00 >;
#declare raio_cena = 6.0;
#declare dir_camera = < 1.00, -1.00, 0.50 >;
#declare dist_camera = 80.0;
#declare intens_luz = 1.00;
camlight(centro_cena, raio_cena, dir_camera, dist_camera , z, intens_luz)