1
// Persistence Of Vision raytracer sample file.
3
// ------------------------------
4
// Features pseudo-Gaussian distribution and use of trace function
5
// Collision algorithm by Greg M. Johnson 2001
6
// ------------------------------
7
// ------------------------------
9
// code by Gilles Tran, derived from work by John Van Sickle and Christoph Hormann
10
// ------------------------------
11
#declare CamD=vnormalize(CamEye-CamLoc); // direction of camera view
12
#declare CamR=vnormalize(vcross(CamSky,CamD)); // to the right
13
#declare CamU=vnormalize(vcross(CamD,CamR)); // camera up
15
#declare Screen= // pseudo screen to test the visibility of an object
20
scale <AspectRatio,1,1>
22
matrix < CamR.x, CamR.y, CamR.z,
23
CamU.x, CamU.y, CamU.z,
24
CamD.x, CamD.y, CamD.z,
25
CamLoc.x,CamLoc.y,CamLoc.z >
27
#macro IsObjectVisible(PosObject)
28
// this macro tests the position of the object against the pseudo screen
29
// note: it also returns false when the position is higher than y=10
30
#local Norm1 = <0, 0, 0>;
31
#local PosTemp= trace (Screen,PosObject,-PosObject+CamLoc,Norm1);
32
#if (vlength(Norm1)!=0 & PosObject.y <10)
38
//object{Screen pigment{rgbf<1,0,0,0.9>}}
40
// ------------------------------
41
// Greg Johnson's algorithm
42
// ------------------------------
43
// cube random position
44
// ------------------------------
46
#local A=360*rand(RRR);
47
#local D=5*(1/rand(RRR)-0.75);
48
#if (D*sin(radians(A))>9) // clipped to let the POVRAY letters visible
55
// ------------------------------
56
// cube placement routine
57
// ------------------------------
59
#declare R2R=seed(1923);
60
#declare S = seed(14400);
61
#declare Norm=<0,0,0>;
65
#declare stored=array[ntests+2][ntests+2]
66
#declare Posy=array[num]
68
#declare Posy[0]=randsq(S);
70
// pseudo box used for collision testing
71
#declare Pseudo=mesh{triangle{0,x,x+z}triangle{0,z,x+z} translate -x*0.5-z*0.5+y*0.5}
73
// ------------------------------
74
// generates the first set of cubes that read POVRAY
75
// ------------------------------
79
#while (i<6) // rotations and positions are put in arrays so that they're the same in the file and in the "ally" object
80
#declare R[i]=<0,-10+25*rand(R2R),0>;
81
#declare T[i]=<-0.5+rand(R2R),0,rand(R2R)-0.5>;
85
object{Pseudo rotate R[0] translate <-4,0.5,-10>+0.35*T[0]}
86
object{Pseudo rotate R[1] translate <-2.50,0.5,-10>+0.35*T[1]}
87
object{Pseudo rotate x*90 rotate R[2] translate <-1,0.5,-10>+0.35*T[2]}
88
object{Pseudo rotate x*90 rotate R[3] translate < 0.50,0.5,-10>+0.35*T[3]}
89
object{Pseudo rotate R[4] translate < 2,0.5,-10>+0.35*T[4]}
90
object{Pseudo rotate R[5] translate < 4,0.5,-10>+0.35*T[5]}
95
#fopen StackFile "stacks.inc" write
96
#write (StackFile, "union{\n")
97
#write (StackFile, "object{unitbox() rotate -90*y rotate ",R[0]," translate <-4,0.5,-10>+0.35*",T[0],"}\n")
98
#write (StackFile, "object{unitbox() rotate ",R[1]," translate <-2.5,0.5,-10>+0.35*",T[1],"}\n")
99
#write (StackFile, "object{unitbox() rotate 90*y rotate ",R[2]," translate <-1,0.5,-10>+0.35*",T[2],"}\n")
100
#write (StackFile, "object{unitbox() rotate 180*y rotate ",R[3]," translate <0.5,0.5,-10>+0.35*",T[3],"}\n")
101
#write (StackFile, "object{unitbox() rotate -90*x rotate ",R[4]," translate <2,0.5,-10>+0.35*",T[4],"}\n")
102
#write (StackFile, "object{unitbox() rotate 90*x rotate ",R[5]," translate <4,0.5,-10>+0.35*",T[5],"}\n")
106
// ------------------------------
107
// main placement loop
108
// runs only if WriteFile is true
109
// ------------------------------
113
#debug concat(str(n,4,0),":")
114
#declare rotey=rand(R2R)*360;
116
#declare okayness=no;
120
#declare testcenter=randsq(S);
121
#declare Visible=IsObjectVisible(testcenter)
130
#declare testpoint=<-0.5,-0.5,-0.5>+<nx/ntests,0,nz/ntests>;
132
#declare tracey=trace(ally,testcenter+y*1000+vaxis_rotate(testpoint,y,rotey),-y,Norm);
135
#declare maxy=tracey.y;
138
#declare stored[nx][nz]=tracey.y;
145
#declare nnnn=int(ntests/2);
147
#if(abs(stored[nnnn][nnnn]-maxy)<0.01)
148
#declare okayness=yes;
153
#declare netbalancevect=<0,0,0>;
160
#if (abs(stored[nx][nz]-maxy)<0.01)
161
#declare netbalancevect=netbalancevect+<nx-nnnn,0,nz-nnnn>;
171
#if (vlength(netbalancevect)<0.5)
172
#declare okayness=yes;
178
#declare counter=counter+100;
181
#declare counter=counter+1;
183
#declare counter=counter+100;
188
#declare Posy[n]=testcenter+<0,maxy+0.5,0>;
189
#declare Visible=IsObjectVisible(Posy[n])
191
#declare R[0]=<int(rand(R2R)*4)*90,0,int(rand(R2R)*4)*90>;
192
#write (StackFile, "object{unitbox() rotate ",R[0]," rotate y*",rotey," translate ", Posy[n],"}\n")
195
object{Pseudo rotate y*rotey translate Posy[n]}
206
#write (StackFile, "}")