// Fabio de Souza Azevedo - RA 952215
// 2021-09-22
//
// TP05

// Exemplo de arquivo de descricao de cena para POV-ray
// Last edited on 2021-12-09 14:23:40 by stolfi

// ======================================================================
// CORES E TEXTURAS

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 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_verde_escuro =
  texture{
    pigment { color rgb <0, 0.5, 0> }
    //finish{ diffuse 0.8 ambient 0.1 specular 0.5 roughness 0.005 }
  }

#declare tx_verde_claro =
  texture{
    pigment { color rgb <0, 1.0, 0> }
    //finish{ diffuse 0.8 ambient 0.1 specular 0.5 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
  }

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

// Partes da cena:

// Pernas

#declare w_pe = 0.25; // largura do pe
#macro pe()
  box {
    <+0.0, -w_pe, 0.0>, <+4*w_pe, +w_pe, +w_pe>
    texture { tx_verde_claro }
  }
#end

#macro pe_tornozelo(ang_pe)
  union {
    sphere { 0, w_pe texture { tx_verde_escuro } }
    object { pe() translate <0,0,-0.5*w_pe> rotate <0,+ang_pe,0> }
  }
#end

#macro canela(ang_pe)
  union {
    sphere { 0, w_pe texture { tx_verde_escuro } }
    cylinder { 0, <8*w_pe, 0.0, 0.0>, 0.7*w_pe texture { tx_verde_claro } }
    object { pe_tornozelo(ang_pe) translate <8*w_pe, 0.0, 0.0> }
  }
#end

#macro perna(ang_joelho, ang_pe)
  union {
    sphere { 0, w_pe texture { tx_verde_escuro } }
    cylinder { 0, <10*w_pe, 0.0, 0.0>, 0.7*w_pe texture { tx_verde_claro } }
    object {
      canela(ang_pe)
      rotate <0, ang_joelho, 0>
      translate <10*w_pe, 0.0, 0.0>
    }
  }
#end

// Braços

#declare w_garra = 0.75*w_pe;
#macro garra1()
  box {
    <+0.0, -w_garra, 0.0>, <+4*w_garra, +w_garra, +w_garra>
    texture { tx_verde_claro }
  }  
#end

#macro garra2()
  box {
    <+0.0, -w_garra, 0.0>, <+4*w_garra, +w_garra, +w_garra>
    texture { tx_verde_claro }
  }  
#end

#macro mao(ang_g1, ang_g2)
  // {ang_g1} = Ângulo da garra 1
  // {ang_g2} = Ângulo da garra 2
  union {
    sphere { 0, w_pe texture { tx_verde_escuro } }
    object { garra1() rotate <0, ang_g1, 0> texture { tx_verde_escuro } }
    object { garra2() rotate <0, ang_g2, 0> texture { tx_verde_escuro } }
  }
#end

#macro antebraco(ang_mao, ang_g1, ang_g2)
  union {
    sphere { 0, w_pe texture { tx_verde_escuro } }
    cylinder { 0, <6*w_pe, 0.0, 0.0>, 0.7*w_pe texture { tx_verde_claro } }
    object { mao(ang_g1, ang_g2) translate <6*w_pe, 0.0, 0.0> }    
  }
#end

#macro braco(ang_cotovelo, ang_mao, ang_g1, ang_g2)
  union {
    sphere { 0, w_pe texture { tx_verde_escuro } }
    cylinder { 0, <6*w_pe, 0.0, 0.0>, 0.7*w_pe texture { tx_verde_claro } }
    object {
      antebraco(ang_mao, ang_g1, ang_g2)
      rotate <0, ang_cotovelo, 0>
      translate <6*w_pe, 0.0, 0.0>
    }
  }
#end


// Robo ainda incompleto... :-)

#macro robo(ang_joelho, ang_pe, ang_cotovelo, ang_mao, ang_g1, ang_g2)
  #local alt = 3.0;
  #local r = 1.0;
  union {
    cylinder { 0, <0, 0, alt>, r texture { tx_verde_claro } }

    // braco direito
    object { braco (ang_cotovelo, ang_mao, ang_g1, ang_g2) translate <r,0,alt> }
    // braco esquerdo
    object { braco (ang_cotovelo, ang_mao, ang_g1, ang_g2) scale <-1,1,1> translate <-r,0,alt> }

    // perna direita
    object { perna(ang_joelho, ang_pe) translate <r, 0, 0> }
    // perna esquerda
    object { perna(ang_joelho, ang_pe) scale <-1,1,1> translate <r, 0, 0> }
  }
#end

#include "eixos.inc"

// Aqui está a cena, finalmente:

object { eixos(8.0) }

//object { perna(45,-30) }
  // ang_joelho, ang_pe

  // robo(ang_joelho, ang_pe, ang_cotovelo, ang_mao, ang_g1, ang_g2)

object { robo(+135, -90,  +90,  +45,  +30,  -30) }
object { robo(+45,  -30,  +15,  +30,  +45,  -45) translate <+4,-4,0> }
object { robo(+60,  -60, +135,  +70,  +60,  -60) translate <-4,+4,0> }

#include "camlight.inc"
#declare centro_cena = < 0.00, 0.00, 0.00 >;
#declare raio_cena = 14.0;
#declare dir_camera = < 7.00, 14.00, 4.00 >;
#declare dist_camera = 8*raio_cena;
#declare intens_luz = 1.20;
camlight(centro_cena, raio_cena, dir_camera, dist_camera , z, intens_luz)