// Exemplo de arquivo de descricao de cena para POV-ray
// Last edited on 2010-03-04 15:44:01 by stolfi

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

background{ color rgb < 0.75, 0.80, 0.85 > }

#declare tx_madeira = 
  texture{
    pigment{ color rgb < 139/255, 69/255, 19/255 > }
    finish{ diffuse 0.8 ambient 0.5 specular 0.5 roughness 0.005 }
  }

#declare tx_azul = 
  texture{
    pigment{ color rgb < 0.1, 0.1, 0.9 > }
    finish{ diffuse 0.8 ambient 0.5 specular 0.5 roughness 0.005 }
  }
  
#declare tx_verde = 
  texture{
    pigment{ color rgb < 0.1, 0.9, 0.1 > }
    finish{ diffuse 0.8 ambient 0.5 specular 0.5 roughness 0.005 }
  }

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

#declare tx_xadrez =
  texture{
    pigment{ checker color rgb < 0.10, 0.12, 0.10 >, color rgb < 1.00, 0.97, 0.90 > }
    finish{ diffuse 0.9 ambient 0.1 }
    scale 2.0
  }
#include "math.inc"
// ======================================================================
// DESCRIÇÃO DA CENA 

#declare ponto =
	sphere {
		<0,0,0>, 0.1	
	}

#include "eixos.inc"
#include "retalho.inc"


#macro interpola4(t0,v0,v1,v2,v3,t1,tt)
	#local v01 = interpola(t0, v0, t1, v1, tt);	
	#local v12 = interpola(t0, v1, t1, v2, tt);	
	#local v23 = interpola(t0, v2, t1, v3, tt);	
	#local v012 = interpola(t0, v01, t1, v12, tt);	
	#local v123 = interpola(t0, v12, t1, v23, tt);	
	#local v0123 = interpola(t0, v012, t1, v123, tt);
	v0123

#end

//interpola da aula 05
#macro interpola(f0,v0,f1,v1,f)
	#local ss = (f-f0)/(f1-f0);
	#local rr = 1 - ss;
	(rr * v0 + ss * v1)
#end

#macro grafico(x0,y0,y1,y2,y3,x3,N)
	union{
		#local inc = (x3-x0)/N;
		#local i = 0;
		#while(i<N)
			#local xx = x0 + inc*i;
			#local yy = interpola4(x0,y0,y1,y2,y3,x3,xx);
			object{ ponto translate yy  }
			#local i = i + 1;
		#end
	
	}
#end

#macro curva(p1,p2,p3,p4,p5,p6,p7,p8,N)
union {
	object{ grafico(1,	 (p8+p1)/2,p1,p2,(p2+p3)/2,	 2,N) texture{ tx_madeira } } 
	object{ grafico(2,	 (p2+p3)/2,p3,p4,(p4+p5)/2,	 3,N) texture{ tx_madeira } }
	object{ grafico(3,	 (p4+p5)/2,p5,p6,(p6+p7)/2,	 4,N) texture{ tx_madeira } } 
	object{ grafico(4,	 (p6+p7)/2,p7,p8,(p8+p1)/2,	 5,N) texture{ tx_madeira } }

}
#end


#macro costura(p11,p12,p13,p21,p22,p23,p31,p32,p33,p41,p42,p43,
	       q12,q13,q14,q22,q23,q24,q32,q33,q34,q42,q43,q44,
	       rad,txg,tx1,tx2)
	       
  union{ 
    object{ retalho(p11,p12,p13,(p13+q12)/2,p21,p22,p23,(p23+q22)/2,p31,p32,p33,(p33+q32)/2,p41,p42,p43,(p43+q42)/2,rad,txg,tx1)}
    object{ retalho((p13+q12)/2,q12,q13,q14,(p23+q22)/2,q22,q23,q24,(p33+q32)/2,q32,q33,q34,(p43+q42)/2,q42,q43,q44,rad,txg,tx2)}
    }    
#end



union{
	object{ curva(<1,1,1>,<1,5,6>,<-2,-3,4>,<-4,-4,-4>,<2,2,2>,<4,-2,1>,<2,-4,-5>,<1,4,1>,200)  translate <-5,0,0>}
	object{ box{<-30,-30,0>, <30,30,-1>} translate <0,0,-5> texture{tx_xadrez}}
	object{ costura(<1,1,1>,<1,2,1>,<1,3,-1>,
			<2,1,2>,<2,3,2>,<2,3,-1>,
			<3,1,3>,<3,3,1>,<3,2,3>, 
			<4,1,0>,<4,2,-3>,<4,3,0>, //fim do primeiro retalho
			<1,5,-2>,<1,6,3>,<1,7,-2>,
			<2,5,-4>,<2,6,0>,<2,7,3>,
			<3,4,0>,<3,7,5>,<3,7,5>,
			<4,5,1>,<4,7,1>,<4,7,1>,
			0.01,tx_azul,tx_verde,tx_vermelho) }
	object{ eixos(15.00) }
} 


#include "camlight.inc"
#declare centro_cena = < 0.00, 0.00, 1.00 >;
#declare raio_cena = 15.0;
#declare dir_camera = < -1.00, 1.00, 1.00 >;
#declare dist_camera = 15.0;
#declare intens_luz = 1.00;
camlight(centro_cena, raio_cena, dir_camera, dist_camera , z, intens_luz)