/* File curvedtri.inc, dated June 26th, 2002 by Ben Chambers. This file creates a triangle version of a bicubic, or bezier, patch. To use, set CURVE_ANGLE (the desired maximum angle between vertex normals of a triangle), and CURVED (an arbitrary curving factor where higher makes curves stick out more). Then, call the macro curved_triangle(va,na,vb,nb,vc,nc) where va, vb and vc are the three vertices, and na, nb and nc are their respective normals. The macro will subdivide the triangles until the desired level of smoothness is reached, even subdividing unevenly along sides (that is, one side may be subdivided to a much higher level than another side of the triangle, depending on their initial normals). Please send any questions or comments to bdchambers79@yahoo.com or, if you're feeling really brave, try my cell phone at (206)713-4382 (US). I look forward to hearing from all you POVers! :) ...Chambers */ #declare CURVE_ANGLE = pi/4; #declare CURVED = 0.5; #macro subdivide(va,na,vb,nb) #local ZZ = acos(vdot(na,nb)/(vlength(na)*vlength(nb)))/pi; ((va+vb)/2+ZZ*vlength(vb-va)*CURVED*vnormalize(na+nb)) #end #macro curved_triangle(va, na, vb, nb, vc, nc) #local aAB=acos(vdot(na,nb)/(vlength(na)*vlength(nb))); #local aAC=acos(vdot(na,nc)/(vlength(na)*vlength(nc))); #local aBC=acos(vdot(nb,nc)/(vlength(nb)*vlength(nc))); #local vab=subdivide(va,na,vb,nb); #local vac=subdivide(va,na,vc,nc); #local vbc=subdivide(vb,nb,vc,nc); #local nab=(na+nb)/2; #local nac=(na+nc)/2; #local nbc=(nb+nc)/2; #if (aAB > CURVE_ANGLE) #if (aAC > CURVE_ANGLE) #if (aBC > CURVE_ANGLE) curved_triangle(va,na,vab,nab,vac,nac) curved_triangle(vb,nb,vab,nab,vbc,nbc) curved_triangle(vc,nc,vac,nac,vbc,nbc) curved_triangle(vab,nab,vac,nac,vbc,nbc) #else curved_triangle(va,na,vab,nab,vac,nac) curved_triangle(vb,nb,vab,nab,vac,nac) curved_triangle(vc,nc,vac,nac,vb,nb) #end #else #if (aBC > CURVE_ANGLE) curved_triangle(vb,nb,vab,nab,vbc,nbc) curved_triangle(vc,nc,vbc,nbc,vab,nab) curved_triangle(va,na,vc,nc,vab,nab) #else curved_triangle(vc,nc,va,na,vab,nab) curved_triangle(vc,nc,vb,nb,vab,nab) #end #end #else #if (aAC > CURVE_ANGLE) #if (aBC > CURVE_ANGLE) curved_triangle(vc,nc,vbc,nbc,vac,nac) curved_triangle(va,na,vac,nac,vbc,nbc) curved_triangle(va,na,vbc,nbc,vb,nb) #else curved_triangle(vb,nb,va,na,vac,nac) curved_triangle(vb,nb,vc,nc,vac,nac) #end #else #if (aBC > CURVE_ANGLE) curved_triangle(va,na,vb,nb,vbc,nbc) curved_triangle(va,na,vc,nc,vbc,nbc) #else smooth_triangle {va,na,vb,nb,vc,nc} #end #end #end #end