// 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_plastico = 
  texture{
    pigment{ color rgb < 0.00, 0.80, 0.00 > }
    finish{ diffuse 0.8 ambient 0.1 specular 0.2 roughness 0.005 }
  }

#declare tx_fosca = 
  texture{
    pigment{ color rgb < 1.00, 0.0, 0.10 > }
    finish{ diffuse 0.9 ambient 0.1 }
  }

#declare tx_xadrez =
  texture{
    pigment{ checker color rgb < 0.10, 0.32, 0.60 >, color rgb < 1.00, 0.97, 0.90 > }
    finish{ diffuse 0.9 ambient 0.1 }
    scale 2.0
  }


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

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

#macro interpola4(t0, v0, v1, v2, v3, t1, tt)
	#local itp01 = interpola(t0, v0, t1, v1, tt);
	#local itp12 = interpola(t0, v1, t1, v2, tt);
	#local itp23 = interpola(t0, v2, t1, v3, tt);
	#local itp012 = interpola(t0, itp01, t1, itp12, tt);
	#local itp123 = interpola(t0, itp12, t1, itp23, tt);
	#local itp0123 = interpola(t0, itp012, t1, itp123, tt);

	itp0123
#end

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


#macro grafico(x0, y0, y1, y2, y3, x3, N)
	#local aux = (x3-x0) / N;
	#local i = 0;
	union {
		#while(i < N)
			#local xaxis = i*aux + x0;
			#local yaxis = interpola4(x0, y0, y1, y2, y3, x3, xaxis);

			object { ponto translate <xaxis, 0, 0> translate yaxis }

			#local i=i+1;
		#end
	}
#end


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


// Aqui está a cena, finalmente:
union{
union{
	object{ grafico(-10, <1,1,1>, <0,0,0>, <8,8,8>, <5,5,5>, -5,15) texture{ tx_fosca } } 
	object{ grafico(-5, <5,5,5>, <2,2,2>, <3,3,3>, <15/2,15/2,-9/2>, 0, 200) texture{ tx_plastico } }
	object{ grafico(0, <15/2,15/2,-9/2>, <12,12,-12>, <5,5,5>, <1/2,1/2,3>, 5, 300) texture{ tx_fosca } } 
	object{ grafico(5, <1/2,1/2,3>, <-4,-4,1>, <0,0,0>, <-1,-1,-1>, 10, 200) texture{ tx_plastico } }  
	scale 0.5
	rotate 270
}

union{
	object{ retalho(<0,0,0>, <1,0,1>, <2,0,1>, <4,0,2>, <0,1,0>, <1,1,1>, <2,1,1>, <4,1,2>, <0,2,0>, <1,2,1>, <2,2,1>,<4,2,2>, <0,3,0>, <1,3,1>, <2,3,1>, <4,3,2>,			0.1, texture{ tx_fosca }, texture{ tx_plastico}) } 

	object{ retalho(<4,0,2>, <6,0,3>, <7,0,3>, <8,0,2>, <4,1,2>, <6,1,3>, <7,1,3>, <8,1,2>, <4,2,2>, <5,2,3>, <6,2,3>, <7,2,2>, <4,3,2>, <5,3,3>, <6,3,3>, <7,3,2>,			0.1, texture{ tx_plastico }, texture{ tx_fosca}) }

translate<6,0,0>
}
}

#include "camlight.inc"
#declare centro_cena = < 2, 0, 0 >;
#declare raio_cena =20;
#declare dir_camera = < 0, 1, 2 >;
#declare dist_camera = 16.0;
#declare intens_luz = 1.00;
camlight(centro_cena, raio_cena, dir_camera, dist_camera , z, intens_luz)