//Lucas Felix 136625
// ======================================================================

background{ color rgb < 0.15, 0.80, 0.55 > }

#declare Yellow = rgb<255, 255, 0>;
#declare Black =  rgb < 0.4, 0.2, 0.8 >;

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

#declare cor_articulacao = 
  texture{
    pigment{ color rgb < 0.50, 0.30, 0.80 > }
  }
 
// ======================================================================
// MATRIZ DE ANGULOS PARA CADA PERNA

 #declare Graus = array[6][4];
 //PERNA 1
 #declare Graus[0][0] = 45;
 #declare Graus[0][1] = 45;
 #declare Graus[0][2] = 45;
 #declare Graus[0][3] = 45;
 
 //PERNA 2
 #declare Graus[1][0] = 45;
 #declare Graus[1][1] = 45;
 #declare Graus[1][2] = 45;
 #declare Graus[1][3] = 45;

//PERNA 3
 #declare Graus[2][0] = 45;
 #declare Graus[2][1] = 45;
 #declare Graus[2][2] = 45;
 #declare Graus[2][3] = 45;

//PERNA 4
 #declare Graus[3][0] = 45;
 #declare Graus[3][1] = 45;
 #declare Graus[3][2] = 45;
 #declare Graus[3][3] = 45;

//PERNA 5
 #declare Graus[4][0] = 45;
 #declare Graus[4][1] = 45;
 #declare Graus[4][2] = 45;
 #declare Graus[4][3] = 45;

//PERNA 6
 #declare Graus[5][0] = 45;
 #declare Graus[5][1] = 45;
 #declare Graus[5][2] = 45;
 #declare Graus[5][3] = 45;

// ======================================================================
// DECLARAÇÃO DOS OBJETOS

#declare P1 =
		union{
		  sphere{
			< 0.00, 0.00, 0.00 >,
			0.5 
			texture{ cor_articulacao }
			}
		  box{
			< -0.5, 0.0, -0.25 >,< 0.5, 2.0, 0.25> texture{ cor_segmento }
			}

	}

#declare P2 =
		union{
		  sphere{
			< 0.00, 0.00, 0.00 >,
			0.5 
			texture{ cor_articulacao }
			}
		  box{
			< -0.5, 0.0, -0.25 >,< 0.5, 3.0, 0.25> texture{ cor_segmento }
			}

	}	

#declare P3 =
		union{
		  sphere{
			< 0.00, 0.00, 0.00 >,
			0.5 
			texture{ cor_articulacao }
			}
		  box{
			< -0.5, 0.0, -0.25 >,< 0.5, 4.0, 0.25> texture{ cor_segmento }
			}

	}	

#declare P4 =
		union{
		  sphere{
			< 0.00, 0.00, 0.00 >,
			0.5 
			texture{ cor_articulacao }
			}
		  box{
			< -0.5, 0.0, -0.25 >,< 0.5, 6.0, 0.25> texture{ cor_segmento }
			}

	}

#declare P5 =
		union{
		  sphere{
			< 0.00, 0.00, 0.00 >,
			0.5 
			texture{ cor_articulacao }
			}
		  box{
			< 0.0, 0.0, -0.25 >,< 0.5, 6.0, 0.25> texture{ cor_segmento }
			}

	}

#declare Corpo =
	union{
		  box{
			< -2.5, 0.0, 0.0 >,< 2.5, 15, 5> texture{ cor_segmento }
			}
	}
	
// ======================================================================
// FUNÇÕES SECUNDARIAS DE CRIAÇÃO DOS MEMBROS

#macro S1()
	object{P1}
#end

#macro S2(Alf)
	union { object {S1() rotate < Alf,0,0 > translate < 0,3,0 > } //Note: a ordem entre rotate e translate IMPORTA!!!
			object {P2}}
#end

#macro S3(Alf,Bet)
	union { object {S2(Alf) rotate < -Bet,0,0 > translate < 0,4,0 > } 
			object {P3}}
#end

#macro S4(Alf,Bet,Gam)
	union { object {S3(Alf,Bet) rotate < Gam,0,0 > translate < 0,6,0 > }
			object {P4}}
#end

#macro Perna(Alf,Bet,Gam,Ro)
	union { object {S4(Alf,Bet,Gam) rotate < -Ro,0,0 > translate < 0,6,0 > }
			object {P5}}
#end

#macro Dragao(Graus)
	union {
			object {Corpo}
			object {Perna(Graus[0][0],Graus[0][1],Graus[0][2],Graus[0][3]) rotate <-90,0,-90> rotate <0,45,0> translate < -2,1,0 >}
			object {Perna(Graus[1][0],Graus[1][1],Graus[1][2],Graus[1][3]) rotate <-90,0,-90> rotate <0,-45,0> translate < 2,1,0 >}
			object {Perna(Graus[2][0],Graus[2][1],Graus[2][2],Graus[2][3]) rotate <-90,0,-90> rotate <0,45,0> translate < -2,7.5,0 >}
			object {Perna(Graus[3][0],Graus[3][1],Graus[3][2],Graus[3][3]) rotate <-90,0,-90> rotate <0,-45,0> translate < 2,7.5,0 >}
			object {Perna(Graus[4][0],Graus[4][1],Graus[4][2],Graus[4][3]) rotate <-90,0,-90> rotate <0,45,0> translate < -2,14,0 >}
			object {Perna(Graus[5][0],Graus[5][1],Graus[5][2],Graus[5][3]) rotate <-90,0,-90> rotate <0,-45,0> translate < 2,14,0 >}
	}
#end

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

#include "eixos.inc"

object{ eixos(3.00) }
Dragao(Graus)

// CAMERA E AFINS
#include "camlight.inc"
#declare centro_cena = < 0.00, 0.00, 1.00 >;
#declare raio_cena = 20.0;
#declare dir_camera = < 14.00, 14.00, 4.00 >;
#declare dist_camera = 34*raio_cena;
#declare intens_luz = 1.20;
camlight(centro_cena, raio_cena, dir_camera, dist_camera , z, intens_luz)