// José Renato Paulon ra 970904
// Last edited on 2003-06-28 12:07:22 by stolfi
// Exercicio 11

#include "colors.inc"
#include "textures.inc"
#include "stones.inc"
#include "finish.inc"

#declare fastclock = clock*2;
#declare fastclock2 = (clock)*2 -1;
#declare temp=1 ;

#declare ang_dir_2  = 0 ;
#declare ang_esq_1  = 3 ;
#declare ang_dir_1  = 3 ; 
#declare temp  = 1;

background{ Gray90 }
#declare cam = <30,25,-100>; // must rotate y*-18
#declare ctr = <30,15,0>;
camera {
  location ctr + 1.0*cam
  right 1.0*x
  up 0.75*y
  sky y
  look_at ctr
}
light_source {
  10*<30,20,0> color 0.8*White
}
light_source {
  10*<-30,35,-20> color 1.2*White
}
light_source {
  10*<7,15,-30> color 0.7*White
}


//sky_sphere{ 
// pigment {Blue_Sky}
//}

#declare tx_madeira =
texture {
	pigment {
       	DMFWood4
       	scale 4
        }
      	finish { Shiny } // pre-defined in finish.inc
	}


//plane {
//	y, -6
//	pigment {Yellow}
    	//texture {tx_madeira}
//}

//Combustor piloto
#declare combustor = union {
	cylinder { <0,0,0>,<0,15,0> 5  pigment {Red} }
	cylinder { <0,0,10>,<0,15,10> 5  pigment {Red} }
	text { ttf "timrom.ttf" "A - Combustor Piloto" 0.25,0  
        pigment{ Yellow } scale <4,4,4> translate <-4,16,-10>}
	translate <8,5,8>	
}
//Bloco Rotativo
#declare bloco = union {
	difference {
		box { <0,0,0>,<10,5,10>  pigment {Gray} scale <3,3,3>}
		object {combustor }
	}
	#declare aleta = box { <0,0,0>,<15,1.5,10>  pigment {Pink} }
	object {aleta translate <2,8,-10>}
	object {aleta translate <2,8,30>}
	cylinder { <30,10,5>,<45,10,5> 2  pigment {Pink} }
	text { ttf "timrom.ttf" "B - Bloco Rotativo" 0.25,0  
        pigment{ Yellow } scale <4,4,4> translate <4,4,-10>}
}

//Mancal Basculante inferior
#declare mancal = union {
	difference {
		box { <0,0,0>,<10,5,10>  pigment {Orange} scale <3,3,3>}
		cylinder { <8,-1,5>,<8,17,5> 2  pigment {Orange} }
		translate <43,0,0>
	}
	text { ttf "timrom.ttf" "C - Mancal Basculante" 0.25,0
        pigment{Yellow} scale <4,4,4> translate <41,4,-10>}

}
//Martelo 
#declare martelo = union {
	cylinder { <0,0,0>,<15,0,0> 1 
        // pigment {Orange} // inútil se tem "texture" -- stolfi
        texture {tx_madeira} }
	cylinder { <0,-3,0>,<0,3,0> 4  pigment { Gray50 } }
	
}	

//Rebimboca
#declare rebimboca = union {
	difference {
 		lathe {
	 		bezier_spline
	 	   	4,
	 	   	<0,0>,<1,4>,<6,7>,<4,11>
	 	   	pigment { Blue }
	 	   	finish {
	 	     		ambient .3
	 	     		phong .75
	 		}	
	 	}
	 	box {
   	 		<-6, 0,6>,  // Near lower left corner
    			< 0, 12,-6>   // Far upper right corner
	  	}
		rotate y*90
		rotate x*-90
		translate <24,13,5>	
	}
	text { ttf "timrom.ttf" "Rebimboca" 0.25,0  
        pigment{ Yellow } scale <4,4,4> translate <28,12,-11>}
}

//Depressionando firmemente a rebimboca
#if (clock <= 0.25)
	object {combustor translate <-20 ,20,0> }
	object {bloco translate <-20 ,0,0> }
	object {martelo rotate y*(90) rotate x*(-90+(clock*200)) translate <10 ,20,-13> }
	object {rebimboca translate <-20 ,0,0> }
	object {mancal}
#end

//Encaixando o combustor
#if (clock > 0.25 & clock <= 0.5)
	object {combustor translate <-20 ,(20-(80*(clock-0.25))),0> }
	object {bloco translate <-20 ,0,0> }
	object {martelo rotate y*(90) rotate x*(40-(clock*200)) translate <10 ,20,-13> }
	object {rebimboca translate <-20 ,0,0> }
	object {mancal}
#end

//Movimento rotatório do bloco rotativo
#if (clock > 0.5 & clock <= 0.75)
	union {
		object {combustor }
		object {bloco }
		object {rebimboca }
		rotate x*(clock-0.5)*160
		translate <-20 ,0,0>	
	}
	object {mancal}
#end

//Encaixe no mancal
#if (clock > 0.75 & clock <= 1)
	union {
		object {combustor}
		object {bloco }
		object {rebimboca }
		rotate x*40
		translate <(-20 +((clock-0.75)*100)) ,0,0>
	}
	object {mancal}
#end