~ubuntu-branches/ubuntu/trusty/arc-gui-clients/trusty

« back to all changes in this revision

Viewing changes to misc/povray_example/blocks/makestacks.inc

  • Committer: Package Import Robot
  • Author(s): Mattias Ellert
  • Date: 2013-05-08 22:45:38 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20130508224538-7kfhy97fg7ncfck0
Tags: 0.4.3-1
New release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Persistence Of Vision raytracer sample file.
 
2
//
 
3
// ------------------------------
 
4
// Features pseudo-Gaussian distribution and use of trace function
 
5
// Collision algorithm by Greg M. Johnson 2001
 
6
// ------------------------------
 
7
// ------------------------------
 
8
// visibility test
 
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
 
14
 
 
15
#declare Screen= // pseudo screen to test the visibility of an object
 
16
  mesh{
 
17
    triangle{0,x,x+y}
 
18
    triangle{0,y,x+y}
 
19
    translate -0.5*(x+y)
 
20
    scale <AspectRatio,1,1>
 
21
    translate CamZoom*z
 
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 >
 
26
  }
 
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)
 
33
        true;
 
34
    #else
 
35
        false;
 
36
    #end
 
37
#end
 
38
//object{Screen pigment{rgbf<1,0,0,0.9>}}
 
39
 
 
40
// ------------------------------
 
41
// Greg Johnson's algorithm
 
42
// ------------------------------
 
43
// cube random position
 
44
// ------------------------------
 
45
#macro randsq(RRR)
 
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
 
49
            #local A = A+180;
 
50
        #end
 
51
        vaxis_rotate(x*D,y,A)
 
52
 
 
53
#end
 
54
 
 
55
// ------------------------------
 
56
// cube placement routine
 
57
// ------------------------------
 
58
 
 
59
#declare R2R=seed(1923);
 
60
#declare S = seed(14400);
 
61
#declare Norm=<0,0,0>;
 
62
 
 
63
#declare ntests=10;
 
64
 
 
65
#declare stored=array[ntests+2][ntests+2]
 
66
#declare Posy=array[num]
 
67
 
 
68
#declare Posy[0]=randsq(S);
 
69
 
 
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}
 
72
 
 
73
// ------------------------------
 
74
// generates the first set of cubes that read POVRAY
 
75
// ------------------------------
 
76
#declare R=array[6]
 
77
#declare T=array[6]
 
78
#declare i=0;
 
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>;
 
82
    #declare i=i+1;
 
83
#end
 
84
#declare ally=union{
 
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]}
 
91
}
 
92
 
 
93
 
 
94
 
 
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")
 
103
 
 
104
 
 
105
 
 
106
// ------------------------------
 
107
// main placement loop
 
108
// runs only if WriteFile is true
 
109
// ------------------------------
 
110
#declare n=1;
 
111
#while(n<num)
 
112
 
 
113
        #debug concat(str(n,4,0),":")
 
114
        #declare rotey=rand(R2R)*360;
 
115
 
 
116
        #declare okayness=no;
 
117
        #declare counter=0 ;
 
118
        #while(counter<50)
 
119
 
 
120
            #declare testcenter=randsq(S);
 
121
            #declare Visible=IsObjectVisible(testcenter)
 
122
            #if (Visible)
 
123
                #declare maxy=-1000;
 
124
 
 
125
                #declare nx=0;
 
126
                #while(nx<ntests)
 
127
                    #declare nz=0;
 
128
                    #while (nz<ntests)
 
129
 
 
130
                        #declare testpoint=<-0.5,-0.5,-0.5>+<nx/ntests,0,nz/ntests>;
 
131
 
 
132
                        #declare tracey=trace(ally,testcenter+y*1000+vaxis_rotate(testpoint,y,rotey),-y,Norm);
 
133
 
 
134
                        #if (maxy<tracey.y)
 
135
                                #declare maxy=tracey.y;
 
136
                        #end
 
137
 
 
138
                        #declare stored[nx][nz]=tracey.y;
 
139
 
 
140
                        #declare nz=nz+1;
 
141
                    #end
 
142
                    #declare nx=nx+1;
 
143
                #end
 
144
 
 
145
                #declare nnnn=int(ntests/2);
 
146
 
 
147
                #if(abs(stored[nnnn][nnnn]-maxy)<0.01)
 
148
                    #declare okayness=yes;
 
149
                    #debug "[y]"
 
150
                #else
 
151
 
 
152
                    #debug "[n]"
 
153
                    #declare netbalancevect=<0,0,0>;
 
154
 
 
155
                    #declare nx=0;
 
156
                    #while(nx<ntests)
 
157
                        #declare nz=0;
 
158
                        #while (nz<ntests)
 
159
 
 
160
                            #if (abs(stored[nx][nz]-maxy)<0.01)
 
161
                                #declare netbalancevect=netbalancevect+<nx-nnnn,0,nz-nnnn>;
 
162
 
 
163
                            #end
 
164
 
 
165
                            #declare nz=nz+1;
 
166
 
 
167
                        #end
 
168
                        #declare nx=nx+1;
 
169
                    #end
 
170
 
 
171
                    #if (vlength(netbalancevect)<0.5)
 
172
                        #declare okayness=yes;
 
173
                    #end
 
174
 
 
175
                #end
 
176
 
 
177
                #if(okayness=yes)
 
178
                    #declare counter=counter+100;
 
179
                #end
 
180
 
 
181
                #declare counter=counter+1;
 
182
            #else
 
183
                #declare counter=counter+100;
 
184
                #debug "[out]"
 
185
            #end
 
186
        #end
 
187
        #if(Visible)
 
188
            #declare Posy[n]=testcenter+<0,maxy+0.5,0>;
 
189
            #declare Visible=IsObjectVisible(Posy[n])
 
190
            #if (Visible)
 
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")
 
193
                #declare ally=union{
 
194
                    object{ally}
 
195
                    object{Pseudo rotate y*rotey translate Posy[n]}
 
196
                }
 
197
            #else
 
198
                #debug "[out]"
 
199
            #end
 
200
        #end
 
201
        #debug "\n"
 
202
 
 
203
#declare n=n+1;
 
204
#end
 
205
 
 
206
#write (StackFile, "}")
 
207
#fclose StackFile