// Priscilla Sanches Marques
// RA : 981944
// MC 930 - Computacao Grafica
// 2 semestre 2000
// Laboratorio 8
// Prof. Stolfi 

#include "colors.inc"
#include "textures.inc"
//
// Definicao das cameras, fundo, spotlight e emissao
//
#declare espessura = 5.00;
#declare amarelado = color rgb (1.0/espessura)*<1.00, 1.00, 0.00>;

#declare posicao = <4.00, 25.00 ,5.00>;
#declare alvo = <3.50, 0.00, 0.00>;
#declare raio = 40.00;

#declare distancia = vlength(posicao - alvo);
#declare abertura = degrees(raio/distancia);

background { color SkyBlue }
plane { y, -10
  pigment {
    checker color White color Black
    scale 20
  }
}

light_source {
  posicao
  color rgb <0.80, 1.00, 0.80>
  spotlight
  point_at alvo
  radius 0.80*abertura falloff 1.20*abertura
  fade_distance distancia
  fade_power 2
}

camera {
  location  < 0.00, 10.00, -17.00 >
  look_at   < 0.00, 0.00, .00 >
} 

//
// Ovos
//

// Textura dos ovos
#declare EggTex = texture {
  pigment { BrightGold }
  finish {
    ambient .1
    diffuse .4
    specular 1
    roughness 0.001
    reflection .5
    metallic
  }
}

// Curva de Bezier que constroi os ovos
#declare Egg = union { // Egg1
  bicubic_patch {
    type 1 flatness 0.0100 u_steps 4 v_steps 4,
    <2.023314, 0.000000, 4.355987>,
    <2.023314, -0.000726, 4.355987>,
    <2.023312, -0.000726, 4.356867>,
    <2.023312, 0.000000, 4.356867>,
    <2.032037, 0.000000, 2.734598>,
    <2.032037, -1.758562, 2.734598>,
    <2.027431, -1.758562, 6.141971>,
    <2.027431, 0.000000, 6.141971>,
    <-1.045672, 0.000000, 3.281572>,
    <-1.045672, -1.758562, 3.281572>,
    <-1.050279, -1.758562, 5.414183>,
    <-1.050279, 0.000000, 5.414183>,
    <-1.044333, 0.000000, 4.341816>,
    <-1.044333, -0.002947, 4.341816>,
    <-1.044341, -0.002947, 4.345389>,
    <-1.044341, 0.000000, 4.345389>
  }
  bicubic_patch {
    type 1 flatness 0.0100 u_steps 4 v_steps 4,
    <2.023312, 0.000000, 4.356867>,
    <2.023312, 0.000726, 4.356867>,
    <2.023314, 0.000726, 4.355987>,
    <2.023314, 0.000000, 4.355987>,
    <2.027431, 0.000000, 6.141971>,
    <2.027431, 1.758562, 6.141971>,
    <2.032037, 1.758562, 2.734598>,
    <2.032037, 0.000000, 2.734598>,
    <-1.050279, 0.000000, 5.414183>,
    <-1.050279, 1.758562, 5.414183>,
    <-1.045672, 1.758562, 3.281572>,
    <-1.045672, 0.000000, 3.281572>,
    <-1.044341, 0.000000, 4.345389>,
    <-1.044341, 0.002947, 4.345389>,
    <-1.044333, 0.002947, 4.341816>,
    <-1.044333, 0.000000, 4.341816>
  }
  texture { EggTex }
  translate <0.5, 0, -5>  // centers the egg around the origin
  translate -9.8*y        // places the egg on the ground
}

//
// Galinha Quasimoda
// 
// tronco + cabeca da galinha
#declare galinha = 
blob {
  threshold 0.65

  // corpo da galinha
  sphere {
    <0.00, 0.00, 0.00>, 5.00, 1
    pigment { color rgbt <1.00, 1.00, 0.00, 1.00> }
  }

  // pescoco da galinha
  cylinder {
    <2.25, 0.00, 0.00>,
    <3.00, 0.00, 0.00>,
    1.00, 1
    pigment { color rgbt <1.00, 1.00, 0.00, 1.00> }
  }

  // cabeca da galinha
  sphere {
    <5.50, 0.00, 0.00>, 
    3.50, 1
    pigment { color rgbt <1.00, 1.00, 0.00, 1.00> }
  }   
  
  //perna direita
  cylinder {
    <-1.00, -2.75 , 0.00>,
    <-1.00, -3.75 , 0.00>,
    0.80 , 1.00
    pigment { color rgbt <1.00, 1.00, 0.00, 1.00> }
  }

  // perna esquerda 
  cylinder {
    <1.00, -2.75 , 0.00>,
    <1.00, -3.75 , 0.00>,
    0.80, 1.00
    pigment { color rgbt <1.00, 1.00, 0.00, 1.00> }
  }

  finish { phong 1 }

}

// bico da galinha
#declare bico =
cone {
  <6.50, 0.00 ,0.00>, 0.75
  <8.50, 0.00 ,0.00>, 0.05
  pigment { color rgbt <0.00, 0.00, 0.00, 0.90> }
  hollow
  interior { 
    media { 
      scattering { 1, color amarelado } 
    }
  }
}

//
// penachos da galinha
//
// penacho vermelho
#declare penacho1 =
cylinder {
  <-1.00, 1.30, 0.00>,
  <-1.00, 2.55, 0.00>,
  0.50
  pigment { color rgbt <1.00, 0.00, 0.00, 0.60> }
  hollow
  interior { 
    media { 
      emission  color amarelado  
    }
  }
}
// penacho verde
#declare penacho2 =
cylinder {
  <-1.50, 1.20, 0.95>,
  <-1.50, 2.45, 0.95>,
  0.50
  pigment { color rgbt <0.00, 1.00, 0.00, 0.60> }
  hollow
  interior { 
    media { 
      emission color amarelado 
    }
  }
}
// penacho vermelho
#declare penacho3 =
cylinder {
  <-0.50, 1.30, -0.95>,
  <-0.50, 2.30, -0.95>,
  0.50
  pigment { color rgbt <0.00, 0.00, 1.00, 0.60> }
  hollow
  interior { 
    media { 
      emission  color amarelado 
    }
  }
}

//
// Tronco + cabeca iluminados
//
#declare corpo =
  object {
    galinha
    hollow
    interior { 
      media { 
        scattering { 1, color amarelado } 
      }
    }
  }

// 
// Quasimoda completa
//
#declare quasimoda =
  merge {
    object { corpo }
    object { bico }
    object { penacho1 }
    object { penacho2 }
    object { penacho3 } 
  }

//
// Ovos que vao aparecer na cena
//
#declare ovos =
merge {
  object { Egg }
  object { Egg translate <8, 0, 8> }
  object { Egg translate <-9, 5, 9> }
  object { Egg translate <15, 10, 12> }
  object { Egg translate <-18, 7, 12> }
}

// A cena final : Quasimoda + ovos perdidos
merge {
  object { ovos }
  object {
    quasimoda
    hollow
    interior { 
      media { 
        scattering { 1, color amarelado } 
      }
    }
  }
}