// UNICAMP
// MC930 - Computacao grafica
// Name: Vitor Hugo Mickus Rodrigues
// Last edit: 09/09/2010

// ======================================================================
// CORES E TEXTURAS
#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_verde = 
  texture{
    pigment{ color rgb < 0.10, 1.00, 0.10 > }
    finish{ diffuse 0.8 ambient 0.1 specular 0.5 roughness 0.005 }
  }

#declare tx_branco = 
  texture{
    pigment{ color rgb < 1.0, 1.00, 1.0 > }
    finish{ diffuse 0.9 ambient 0.1 }
  }

#declare tx_preto = 
  texture{
    pigment{ color rgb < 0.0, 0.00, 0.0 > }
    finish{ diffuse 0.9 ambient 0.1 }
  }

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

#declare tx_fosca = 
  texture{
    pigment{ color rgb < 1.00, 0.80, 0.10 > }
    finish{ diffuse 0.9 ambient 0.1 }
  }

#declare tx_espelho = 
  texture{
    pigment{ color rgb < 1.00, 0.85, 0.30 > }
    finish{ diffuse 0.2 reflection 0.7*< 1.00, 0.85, 0.30 > ambient 0.1 }
  }

#declare tx_vidro = 
  texture{
    pigment{ color rgb < 0.85, 0.95, 1.00 > filter 0.70 }
    finish{ diffuse 0.03 reflection 0.25 ambient 0.02 specular 0.25 roughness 0.005 }
  }

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

#include "textures.inc"
#include "eixos.inc"

/*  Contents:
    ===========================
    DMFWood6
    NBglass            (Norm Bowler)
    NBoldglass         (Norm Bowler)
    NBwinebottle       (Norm Bowler)
    NBbeerbottle       (Norm Bowler)
    Ruby_Glass         (after Norm Bowler)
    Dark_Green_Glass   (after Norm Bowler)
    Yellow_Glass       (after Norm Bowler)
    Orange_Glass       (after Norm Bowler)
    Vicks_Bottle_Glass (after Norm Bowler)
    Soft_Silver        (Dan Farmer)
    New_Penny          (Dan Farmer)
    Tinny_Brass        (Dan Farmer)
    Gold_Nugget        (Dan Farmer)
    Aluminum           (Dan Farmer)
    Bright_Bronze      (Dan Farmer)
    Lightening1        (Dan Farmer)
    Lightening2        (Dan Farmer)
    Brushed_Aluminum   (Dan Farmer)
    Starfield          (Jeff Burton )
    Shadow_Clouds      (Bill Pulver)
*/


// Partes da cena:
// =====================================================================

#declare corpo = union {

  sphere{<-0.6,0,0> 1 texture{tx_fosca}}
  cylinder{<-0.7,0,0>, <0.7,0,0> 1 texture{tx_fosca} }
  sphere{<0.6,0,0> 1 texture{tx_fosca}}
  
}

#declare pescoco = cylinder {<0.8,0,1>,<1.3,0,1.6> 0.2 texture{tx_vermelho}}

#declare cabeca = sphere{<1.8,0,2.3> 0.8 texture{tx_fosca}}

#declare bico = cone{
  <2.6,0,2.3>, 0.2 
  <3.3,0,2.3>, 0 
  texture{tx_vermelho}
}


#macro pe()
  
  union{
    box{<0,0,-1.1> <0.6, 0.3,-1.3>}
    box{<0,-0.9,-1.1> <0.6,-1.2,-1.3>}    
  }
  
  
#end //end of pe

#macro anteperna (alph)
  union {
    cylinder{<0, 0, 0> <0,0,-1.1> 0.2 texture{tx_vermelho} }  
    cylinder{<0, -1.3, 0> <0,-1.3,-1.1> 0.2 texture{tx_vermelho} }    
    object{pe() rotate y*alph translate<0.1,-0.1,0.1>  }
  }
  
#end //end of anteperna

//envolve a coxa, a canela e o pe
#macro perna(alph,beta)
  union {
    cylinder{ <0, 0, 0>, <0,0,-0.8>, 0.2 texture{tx_vermelho} }  
    cylinder{<0,-1.2,0> <0,-1.2,-0.8> 0.2 texture{tx_vermelho}}  
    object{ anteperna(alph) rotate y*beta translate <0,0,-0.8>}
  }
#end //end of perna

#macro galinha(alph,beta,gama) 
  union{
    object{pescoco}
    object{corpo}
    object{cabeca}
    object{bico}
    object{perna(alph,beta) rotate y*gama translate<0,0.6,-0.6> }
  }
#end//end of galinha

// =====================================================================
// DESCRIÇÃO DA CENA 

//variaveis tempo
#declare t0=0;
#declare t1=0.25;
#declare t2=0.5;
#declare t3=0.75;
#declare t4=1;

//variaveis angulo
#declare alph0=0;
#declare alph1=10;
#declare alph2=15;
#declare alph3=10;
#declare alph4=0;

//variaveis angulo
#declare beta0=45;
#declare beta1=30;
#declare beta2=0;
#declare beta3=30;
#declare beta4=45;

//variaveis angulo
#declare gama0=-45;
#declare gama1=-20;
#declare gama2=0;
#declare gama3=-20;
#declare gama4=-45;


#macro interpola(ta,va,tb,vb,tt)
  #local s = (tt-ta)/(tb-ta);
  ((1-s)*va+s*vb)
#end



//se clock entre t0 e t1
#if ((clock >= t0) & (clock <= t1))
  
  #declare alph = interpola(t0,alph0,t1,alph1,clock);
  #declare beta = interpola(t0,beta0,t1,beta1,clock);
  #declare gama = interpola(t0,gama0,t1,gama1,clock);
  
#end


//se clock entre t1 e t2
#if ((clock >= t1) & (clock <= t2))
  
  #declare alph = interpola(t1,alph1,t2,alph2,clock);
  #declare beta = interpola(t1,beta1,t2,beta2,clock);
  #declare gama = interpola(t1,gama1,t2,gama2,clock);
  
#end

//se clock entre t2 e t3
#if ((clock >= t2) & (clock <= t3))
  
  #declare alph = interpola(t2,alph2,t3,alph3,clock);
  #declare beta = interpola(t2,beta2,t3,beta3,clock);
  #declare gama = interpola(t2,gama2,t3,gama3,clock);
  
#end

//se clock entre t3 e t4
#if ((clock >= t3) & (clock <= t4))
  
  #declare alph = interpola(t3,alph3,t4,alph4,clock);
  #declare beta = interpola(t3,beta3,t4,beta4,clock);
  #declare gama = interpola(t3,gama3,t4,gama4,clock);
  
#end


background{ color rgb < 0.75, 0.80, 0.85 > }
//object{eixos(3)}
object{galinha(alph,beta,gama) translate <0,0,sin(3 + 2*pi*clock)>}




#include "camlight.inc"
#declare centro_cena = < 0.00, 2.00, 0.00 >;
#declare raio_cena = 10.0;
#declare dir_camera = < 3.00, 3.00, 2.00 >;
#declare dist_camera = 20.0;
#declare intens_luz = 1.00;

camlight(centro_cena, raio_cena, dir_camera, dist_camera , z, intens_luz)