// Last edited on 2007-07-23 23:31:39 by stolfi
// Processed by remove-cam-lights

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

// plane {z, -5
//  pigment {
//   checker color rgb <0.8,0.8,0.9>,
//     color rgbf <1,1,1, 0.8>
//  }
// finish {reflection 0.5}
// }

#declare Boca =
texture {
 pigment { color rgb < 0.2,0.2 , 0.5> filter 0.2}
 finish { specular 0.5 roughness 0.005 ambient 0.3 ior 1.1 reflection 0.05}
}

#declare Olho =
texture {
 pigment { color rgb < 0.3, 0.9, 0.4> filter 0.5}
 finish { specular 0.1 roughness 0.005 ambient 0.1 ior 1.3}
}

#declare Pele =
  texture {
    pigment { color rgb < 0.60, 0.70, 0.55 > }
    finish { ambient 0.6 diffuse 0.8 phong 0.5 reflection 0.05 roughness 0.05 brilliance 0.6 }
  }

#declare Espada =
  texture {
    pigment { color rgb < 0.30, 0.30, 0.40 > }
    finish { ambient 0.6 phong 0.5 reflection 0.7 roughness 0.05 brilliance 0.6 }
  }

#declare cabeca =
union {
difference {
 object{
 sphere {
  <0,0,0>, 1.6
  texture {Pele}
 }
 }
 object {
  box {
  <-2.1,0,-0.2>
  <2.1, 2.1, 0.2>
  texture {Boca}
  }
 }
}
object {
 sphere {
 <0,0,0>, 0.5
 texture {Olho}
 translate <0.9, 1.2, 1.2>
 }
 }
object {
 sphere {
 <0,0,0>, 0.5
 texture {Olho}
 translate <-0.9, 1.2, 1.2>
 }
 }
}

#declare corpo =
union {
object {
 sphere{
 <0,0,0>, 6
 scale <0.3, 0.3, 0.7>
 texture {Pele}
 }
}

object {
 sphere {
 <1.1, 0, 3.3>, 0.8
 texture {Pele}
}
}
object {
 sphere {
 <-1.1, 0, 3.3>, 0.8
 texture {Pele}
}
}
object {
 sphere {
 <1.8, 0, -0.4>, 0.8
 texture {Pele}
}
}
object {
 sphere {
 <-1.8, 0, -0.4>, 0.8
 texture {Pele}
}
}
}

#declare antebraco =
union {
  object {
 cylinder {
 < 0.00, 0.00, 0.00 >,
 < 0.00, 0.00, -2.0 >,
 0.5
 texture { Pele }
 }
  }
  object {
 sphere {
 < 0, 0, -2.4 >, 0.8
 texture { Pele }
 }
  }
}

#macro braco (angulo_antebraco)
union {
 cylinder {
 < 0.00, 0.00, 0.00 >,
 < 0.00, 0.00, -2.0 >,
 0.5
 texture { Pele }
 }
 object {
  sphere {
  < 0, 0, -2.4 >, 0.8
  texture { Pele }
  }
 }
 object {
  antebraco
  rotate angulo_antebraco * x
  translate -2.4 * z
 }
}
#end

#macro braco_arma (angulo_antebraco)
union {
 cylinder {
 < 0.00, 0.00, 0.00 >,
 < 0.00, 0.00, -2.0 >,
 0.5
 texture { Pele }
 }
 object {
  sphere {
  < 0, 0, -2.4 >, 0.8
  texture { Pele }
  }
 }
 object {
 union {
 object{antebraco}
 object{
 cylinder {
 <0,0,-3.2>
 <0,0,-4> 0.2
 texture{Espada}
 }
 }
 object {
 cone {
 <0,0,-4>, 0.4
 <0,0,-11>, 0
 texture{Espada}
 }
 }
 }
  rotate angulo_antebraco * x
  translate -2.4 * z
 }
}
#end

#macro move(Amplitude)
Amplitude*cos(clock*2*pi)
#end

#declare tempo = 4*clock*clock - 4*clock + 1;

#declare angulo_cabeca = 30 * (-clock) + 10;
#declare rotacao_cabeca = 0;

#declare angulo_antebraco_dianteiro_d = 90 * (1-tempo) + 30;
#declare angulo_braco_dianteiro_yd = -90 * (1 - tempo) - 10;
#declare angulo_braco_dianteiro_xd = 60 * (1-tempo) + 60;

#declare angulo_antebraco_dianteiro_e = 120 * (1-tempo) + 30 ;
#declare angulo_braco_dianteiro_ye = 60;
#declare angulo_braco_dianteiro_xe = clock * -60;

#declare angulo_antebraco_traseiro_d = (-40 * tempo) -20;
#declare angulo_braco_traseiro_yd = -20;
#declare angulo_braco_traseiro_xd = move(45);

#declare angulo_antebraco_traseiro_e = (-40 * tempo) -20;
#declare angulo_braco_traseiro_ye = 20;
#declare angulo_braco_traseiro_xe = move(-45);

#declare PEX = 2*(sin(angulo_braco_traseiro_xe) + sin(180-angulo_antebraco_traseiro_e-angulo_braco_traseiro_xe));
#declare PEY = 2*(cos(angulo_braco_traseiro_xe) + cos(180-angulo_antebraco_traseiro_e-angulo_braco_traseiro_xe));
#declare PDX = 2*(sin(angulo_braco_traseiro_xd) + sin(180-angulo_antebraco_traseiro_d+angulo_braco_traseiro_xd));
#declare PDY = 2*(cos(angulo_braco_traseiro_xd) + cos(180-angulo_antebraco_traseiro_d+angulo_braco_traseiro_xd));

#macro sapinho (ang_cabeca, giro_cabeca, ang_ant_frente_d, ang_braco_frente_yd, ang_braco_frente_xd, ang_ant_frente_e, ang_braco_frente_ye, ang_braco_frente_xe, ang_ant_tras_d, ang_braco_tras_yd, ang_braco_tras_xd, ang_ant_tras_e, ang_braco_tras_ye, ang_braco_tras_xe)
union {
object {corpo}
union {
object {braco_arma (ang_ant_frente_d) rotate ang_braco_frente_yd * y rotate ang_braco_frente_xd * x translate <1.1,0,3.3>}
object {braco (ang_ant_frente_e) rotate ang_braco_frente_ye * y rotate ang_braco_frente_xe * x translate <-1.1,0,3.3>}
object {braco (ang_ant_tras_d) rotate ang_braco_tras_yd * y rotate ang_braco_tras_xd * x translate <1.8,0,-0.4>}
object {braco (ang_ant_tras_e) rotate ang_braco_tras_ye * y rotate ang_braco_tras_xe * x translate <-1.8,0,-0.4>}
object {cabeca rotate ang_cabeca * x rotate giro_cabeca * z translate <0,0,5.5> }
}
}

translate <-PEX, 0, -PEY>
#end

object {sapinho (angulo_cabeca, rotacao_cabeca, angulo_antebraco_dianteiro_d, angulo_braco_dianteiro_yd, angulo_braco_dianteiro_xd, angulo_antebraco_dianteiro_e, angulo_braco_dianteiro_ye, angulo_braco_dianteiro_xe, angulo_antebraco_traseiro_d, angulo_braco_traseiro_yd, angulo_braco_traseiro_xd, angulo_antebraco_traseiro_e, angulo_braco_traseiro_ye, angulo_braco_traseiro_xe)}

// Original camera parameters:
// #local cam_ctr = <0,0,0>
// #local cam_vec = <-20.00,30.00,4.00>
// #local cam_sky = z

#include "camlight.inc"
// camlight(<0,0,0>,<10,10,10>,20.0,z,1.0)
camlight(<0,0,2>,<7,10,5>,23.0,z,1.0)