23 |
|
* sort of context, so it is impossible to simultaneously run |
24 |
|
* this library on multiple scenes or in multiple threads. |
25 |
|
* You get one scene and one thread, and if you want more, you |
26 |
< |
* will have to go with the process model used by the programs |
27 |
< |
* gen/mkillum, hd/rholo, and px/pinterp. Finally, unrecoverable |
28 |
< |
* errors result in a call to the application-defined function |
29 |
< |
* quit(). The usual thing to do is to call exit(). |
26 |
> |
* will have to go with the process model defined in raypcalls.c. |
27 |
> |
* Finally, unrecoverable errors result in a call to the application- |
28 |
> |
* defined function quit(). The usual thing to do is to call exit(). |
29 |
|
* You might want to do something else instead, like |
30 |
|
* call setjmp()/longjmp() to bring you back to the calling |
31 |
|
* function for recovery. You may also wish to define your own |
90 |
|
*/ |
91 |
|
|
92 |
|
#include <string.h> |
93 |
+ |
#include <time.h> |
94 |
|
|
95 |
|
#include "ray.h" |
96 |
|
#include "source.h" |
115 |
|
|
116 |
|
void (*trace)() = NULL; /* trace call */ |
117 |
|
|
118 |
– |
extern void ambnotify(); |
118 |
|
void (*addobjnotify[8])() = {ambnotify, NULL}; |
119 |
|
|
120 |
|
int do_irrad = 0; /* compute irradiance? */ |
121 |
|
|
122 |
+ |
int rand_samp = 0; /* pure Monte Carlo sampling? */ |
123 |
+ |
|
124 |
|
double dstrsrc = 0.0; /* square source distribution */ |
125 |
|
double shadthresh = .03; /* shadow threshold */ |
126 |
|
double shadcert = .75; /* shadow certainty */ |
154 |
|
int ambincl = -1; /* include == 1, exclude == 0 */ |
155 |
|
|
156 |
|
|
157 |
< |
void |
158 |
< |
ray_init(otnm) /* initialize ray-tracing calculation */ |
159 |
< |
char *otnm; |
157 |
> |
extern void |
158 |
> |
ray_init( /* initialize ray-tracing calculation */ |
159 |
> |
char *otnm |
160 |
> |
) |
161 |
|
{ |
162 |
|
if (nobjects > 0) /* free old scene data */ |
163 |
|
ray_done(0); |
166 |
|
initotypes(); |
167 |
|
/* initialize urand */ |
168 |
|
initurand(2048); |
169 |
+ |
srandom(rand_samp ? (long)time(0) : 0L); |
170 |
|
/* read scene octree */ |
171 |
|
readoct(octname = otnm, ~(IO_FILES|IO_INFO), &thescene, NULL); |
172 |
|
nsceneobjs = nobjects; |
177 |
|
/* ready to go... */ |
178 |
|
} |
179 |
|
|
180 |
< |
void |
181 |
< |
ray_trace(r) /* trace a primary ray */ |
182 |
< |
RAY *r; |
180 |
> |
extern void |
181 |
> |
ray_trace( /* trace a primary ray */ |
182 |
> |
RAY *r |
183 |
> |
) |
184 |
|
{ |
185 |
< |
rayorigin(r, NULL, PRIMARY, 1.0); |
186 |
< |
samplendx++; |
185 |
> |
rayorigin(r, PRIMARY, NULL, NULL); |
186 |
> |
samplendx = rand_samp ? random() : samplendx+1; |
187 |
|
rayvalue(r); /* assumes origin and direction are set */ |
188 |
|
} |
189 |
|
|
190 |
|
|
191 |
< |
void |
192 |
< |
ray_done(freall) /* free ray-tracing data */ |
193 |
< |
int freall; |
191 |
> |
extern void |
192 |
> |
ray_done( /* free ray-tracing data */ |
193 |
> |
int freall |
194 |
> |
) |
195 |
|
{ |
196 |
|
retainfonts = 1; |
197 |
|
ambdone(); |
209 |
|
initurand(0); |
210 |
|
} |
211 |
|
if (nobjects > 0) { |
212 |
< |
sprintf(errmsg, "%d objects left after call to ray_done()", |
212 |
> |
sprintf(errmsg, "%ld objects left after call to ray_done()", |
213 |
|
nobjects); |
214 |
|
error(WARNING, errmsg); |
215 |
|
} |
216 |
|
} |
217 |
|
|
218 |
|
|
219 |
< |
void |
220 |
< |
ray_save(rp) /* save current parameter settings */ |
221 |
< |
RAYPARAMS *rp; |
219 |
> |
extern void |
220 |
> |
ray_save( /* save current parameter settings */ |
221 |
> |
RAYPARAMS *rp |
222 |
> |
) |
223 |
|
{ |
224 |
|
int i, ndx; |
225 |
|
|
267 |
|
} |
268 |
|
|
269 |
|
|
270 |
< |
void |
271 |
< |
ray_restore(rp) /* restore parameter settings */ |
272 |
< |
RAYPARAMS *rp; |
270 |
> |
extern void |
271 |
> |
ray_restore( /* restore parameter settings */ |
272 |
> |
RAYPARAMS *rp |
273 |
> |
) |
274 |
|
{ |
275 |
|
register int i; |
276 |
|
|
335 |
|
} |
336 |
|
|
337 |
|
|
338 |
< |
void |
339 |
< |
ray_defaults(rp) /* get default parameter values */ |
340 |
< |
RAYPARAMS *rp; |
338 |
> |
extern void |
339 |
> |
ray_defaults( /* get default parameter values */ |
340 |
> |
RAYPARAMS *rp |
341 |
> |
) |
342 |
|
{ |
343 |
|
int i; |
344 |
|
|
366 |
|
memset(rp->ambfile, '\0', sizeof(rp->ambfile)); |
367 |
|
rp->ambvwt = 0; |
368 |
|
rp->ambres = 256; |
369 |
< |
rp->ambacc = 0.1; |
369 |
> |
rp->ambacc = 0.15; |
370 |
|
rp->ambdiv = 1024; |
371 |
|
rp->ambssamp = 512; |
372 |
|
rp->ambounce = 0; |