// Exercicio 8 - MC930
// Nilton Volpato - RA 003243
// Tuba canora e computosa
// Imagem 400x200 pixels ou proporcional

#include "colors.inc"
#include "textures.inc"
#include "woods.inc"
#include "golds.inc"
#include "metals.inc"

#default { finish { ambient 0.1 } }

background { color LightBlue }

//----------------------------------------------
// Luzes, Câmeras, ...

light_source {
  < -12.00, 18.00, -40.00 >
  color rgb < .5, .5, .5 >
}

light_source {
  <-12, 30, -45>
  color White
  spotlight
  radius 18
  falloff 20
  tightness 10
  point_at <0,0,0>
}

camera {
  location  < 0, 10, -30 >
  right <1,0,0>
  up <0,.5,0>
  look_at   0
  //rotate <0,-75,0>
} 


//----------------------------------------------
// Cores e Texturas

#declare cor_corpo_violao =
  texture {
    T_Wood10
  }

#declare cor_braco_violao =
  texture {
    T_Wood1
  }

#declare cor_cone_tuba =
  texture {
    T_Gold_4A
  }

#declare cor_corda =
  texture {
    T_Brass_1A
  }

#declare metal_polido =
  texture {
    //Polished_Chrome
    //T_Chrome_5B
    T_Silver_5B
  }

//----------------------------------------------
// Partes da Tuba

// Corpo do Violão
#declare corpo_violao =
  union {
    prism {
      cubic_spline
      -1.2, // altura 1
      1.2,  // altura 2
      15, // número de pontos
      <2,5>, // ponto de controle
      <0,6>, // ponto inicial
      <-2,5.5>,
      <-3,4>,
      <-2,1>,
      <-4,-4>,
      <-3,-6>,
      <0,-7>,
      <3,-6>,
      <4,-4>,
      <2,1>,
      <3,4>,
      <2,5.5>,
      <0,6>, // ponto final = ponto inicial
      <-2,5>
      texture { cor_corpo_violao }
      rotate <0,90,0>
    }
    box { 0.5*<-1, -1, -1>, 0.5*< 1,  1,  1>
      scale <0.5,0,2>
      translate <-5,1.2,0>
      texture { metal_polido }
    }

  }

// Braço do Violão
#declare braco_violao =
  union {
    prism {
      quadratic_spline
      -.5, .5,
      10, // número de pontos
      <.7,8>,
      <0,0>, <-.7,0>, <-.7,8>, <-1.4,12>, <1.4,11>, <.7,8>, <.7,0>, <0,0>,
      <-.7,8>
      texture { cor_braco_violao }
      rotate <0,90,0>
    }
    box { 0.5*<-1, -1, -1>, 0.5*< 1,  1,  1>
      scale <0.5,0.2,1.5>
      translate <10,1.2,0>
      texture { metal_polido }
    }
    #declare i = 1;
    #while ( i < 9 )
      cylinder {
	<i,.5,0.7>, <i,.5,-0.7>, 0.05
	texture { metal_polido }
      }
      #declare i = i+1;
    #end
  }


// Cone da Tuba
#declare cone_tuba =
  lathe {
    bezier_spline
    4,
    <1,0>,
    <2,5>,
    <3,7>,
    <5,7>
    scale 0.8
    texture { cor_cone_tuba }
    finish { ambient .1 }
    rotate <0,90,0>
  }

// Corda do Violão
#declare corda = 
  cylinder {
    <-5,0,0>, <16,0,0>, 0.04
    texture { cor_corda }
  }




//----------------------------------------------
// Objeto Final

#declare tuba_violosa =
  union {
    object { corpo_violao }
    object { braco_violao translate <6,1.2-0.5,0>}
    object { corda translate <0,1.4, 0.5> }
    object { corda translate <0,1.4, 0.3> }
    object { corda translate <0,1.4, 0.1> }
    object { corda translate <0,1.4,-0.1> }
    object { corda translate <0,1.4,-0.3> }
    object { corda translate <0,1.4,-0.5> }
    
    object { cone_tuba translate <-1,1.1,0> }
    
    rotate <-90,0,0>
  }


//----------------------------------------------
// Cena

object { 
  tuba_violosa 
  rotate <0,-35,0>
  translate <0,1.5,0>
}


plane {
  y,
  -10
  pigment { checker color Black color White scale 5 }
}