1 |
– |
/* Copyright (c) 1995 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* raytrace.c - routines for tracing and shading rays. |
6 |
|
* |
7 |
< |
* 8/7/85 |
7 |
> |
* External symbols declared in ray.h |
8 |
|
*/ |
9 |
|
|
10 |
< |
#include "ray.h" |
10 |
> |
#include "copyright.h" |
11 |
|
|
12 |
< |
#include "octree.h" |
13 |
< |
|
12 |
> |
#include "ray.h" |
13 |
> |
#include "source.h" |
14 |
|
#include "otypes.h" |
18 |
– |
|
15 |
|
#include "otspecial.h" |
16 |
+ |
#include "random.h" |
17 |
|
|
18 |
|
#define MAXCSET ((MAXSET+1)*2-1) /* maximum check set size */ |
19 |
|
|
23 |
– |
extern CUBE thescene; /* our scene */ |
24 |
– |
extern int maxdepth; /* maximum recursion depth */ |
25 |
– |
extern double minweight; /* minimum ray weight */ |
26 |
– |
extern int do_irrad; /* compute irradiance? */ |
27 |
– |
extern COLOR ambval; /* ambient value */ |
28 |
– |
|
29 |
– |
extern COLOR cextinction; /* global extinction coefficient */ |
30 |
– |
extern double salbedo; /* global scattering albedo */ |
31 |
– |
extern double seccg; /* global scattering eccentricity */ |
32 |
– |
extern double ssampdist; /* scatter sampling distance */ |
33 |
– |
|
20 |
|
unsigned long raynum = 0; /* next unique ray number */ |
21 |
|
unsigned long nrays = 0; /* number of calls to localhit */ |
22 |
|
|
23 |
< |
static FLOAT Lambfa[5] = {PI, PI, PI, 0.0, 0.0}; |
23 |
> |
static RREAL Lambfa[5] = {PI, PI, PI, 0.0, 0.0}; |
24 |
|
OBJREC Lamb = { |
25 |
|
OVOID, MAT_PLASTIC, "Lambertian", |
26 |
|
{0, 5, NULL, Lambfa}, NULL, |
28 |
|
|
29 |
|
OBJREC Aftplane; /* aft clipping plane object */ |
30 |
|
|
45 |
– |
static int raymove(), checkset(), checkhit(); |
46 |
– |
|
47 |
– |
#define MAXLOOP 128 /* modifier loop detection */ |
48 |
– |
|
31 |
|
#define RAYHIT (-1) /* return value for intercepted ray */ |
32 |
|
|
33 |
+ |
static int raymove(FVECT pos, OBJECT *cxs, int dirf, RAY *r, CUBE *cu); |
34 |
+ |
static int checkhit(RAY *r, CUBE *cu, OBJECT *cxs); |
35 |
+ |
static void checkset(OBJECT *os, OBJECT *cs); |
36 |
|
|
37 |
< |
rayorigin(r, ro, rt, rw) /* start new ray from old one */ |
38 |
< |
register RAY *r, *ro; |
39 |
< |
int rt; |
40 |
< |
double rw; |
37 |
> |
|
38 |
> |
extern int |
39 |
> |
rayorigin( /* start new ray from old one */ |
40 |
> |
RAY *r, |
41 |
> |
int rt, |
42 |
> |
const RAY *ro, |
43 |
> |
const COLOR rc |
44 |
> |
) |
45 |
|
{ |
46 |
+ |
double rw, re; |
47 |
+ |
/* assign coefficient/weight */ |
48 |
+ |
if (rc == NULL) { |
49 |
+ |
rw = 1.0; |
50 |
+ |
setcolor(r->rcoef, 1., 1., 1.); |
51 |
+ |
} else { |
52 |
+ |
rw = intens(rc); |
53 |
+ |
if (rc != r->rcoef) |
54 |
+ |
copycolor(r->rcoef, rc); |
55 |
+ |
} |
56 |
|
if ((r->parent = ro) == NULL) { /* primary ray */ |
57 |
|
r->rlvl = 0; |
58 |
|
r->rweight = rw; |
61 |
|
r->clipset = NULL; |
62 |
|
r->revf = raytrace; |
63 |
|
copycolor(r->cext, cextinction); |
64 |
< |
r->albedo = salbedo; |
64 |
> |
copycolor(r->albedo, salbedo); |
65 |
|
r->gecc = seccg; |
66 |
|
r->slights = NULL; |
67 |
|
} else { /* spawned ray */ |
68 |
+ |
if (ro->rot >= FHUGE) { |
69 |
+ |
memset(r, 0, sizeof(RAY)); |
70 |
+ |
return(-1); /* illegal continuation */ |
71 |
+ |
} |
72 |
|
r->rlvl = ro->rlvl; |
73 |
|
if (rt & RAYREFL) { |
74 |
|
r->rlvl++; |
82 |
|
} |
83 |
|
r->revf = ro->revf; |
84 |
|
copycolor(r->cext, ro->cext); |
85 |
< |
r->albedo = ro->albedo; |
85 |
> |
copycolor(r->albedo, ro->albedo); |
86 |
|
r->gecc = ro->gecc; |
87 |
|
r->slights = ro->slights; |
85 |
– |
r->rweight = ro->rweight * rw; |
88 |
|
r->crtype = ro->crtype | (r->rtype = rt); |
89 |
|
VCOPY(r->rorg, ro->rop); |
90 |
+ |
r->rweight = ro->rweight * rw; |
91 |
+ |
/* estimate extinction */ |
92 |
+ |
re = colval(ro->cext,RED) < colval(ro->cext,GRN) ? |
93 |
+ |
colval(ro->cext,RED) : colval(ro->cext,GRN); |
94 |
+ |
if (colval(ro->cext,BLU) < re) re = colval(ro->cext,BLU); |
95 |
+ |
re *= ro->rot; |
96 |
+ |
if (re > 0.1) |
97 |
+ |
if (re > 92.) |
98 |
+ |
r->rweight = 0.0; |
99 |
+ |
else |
100 |
+ |
r->rweight *= exp(-re); |
101 |
|
} |
102 |
|
rayclear(r); |
103 |
+ |
if (r->rweight <= 0.0) /* check for expiration */ |
104 |
+ |
return(-1); |
105 |
+ |
if (r->crtype & SHADOW) /* shadow commitment */ |
106 |
+ |
return(0); |
107 |
+ |
if (maxdepth <= 0 && rc != NULL) { /* Russian roulette */ |
108 |
+ |
if (minweight <= 0.0) |
109 |
+ |
error(USER, "zero ray weight in Russian roulette"); |
110 |
+ |
if (maxdepth < 0 && r->rlvl > -maxdepth) |
111 |
+ |
return(-1); /* upper reflection limit */ |
112 |
+ |
if (r->rweight >= minweight) |
113 |
+ |
return(0); |
114 |
+ |
if (frandom() < r->rweight/minweight) |
115 |
+ |
return(-1); |
116 |
+ |
rw = minweight/r->rweight; /* promote survivor */ |
117 |
+ |
scalecolor(r->rcoef, rw); |
118 |
+ |
r->rweight = minweight; |
119 |
+ |
return(0); |
120 |
+ |
} |
121 |
|
return(r->rlvl <= maxdepth && r->rweight >= minweight ? 0 : -1); |
122 |
|
} |
123 |
|
|
124 |
|
|
125 |
< |
rayclear(r) /* clear a ray for (re)evaluation */ |
126 |
< |
register RAY *r; |
125 |
> |
extern void |
126 |
> |
rayclear( /* clear a ray for (re)evaluation */ |
127 |
> |
register RAY *r |
128 |
> |
) |
129 |
|
{ |
130 |
|
r->rno = raynum++; |
131 |
|
r->newcset = r->clipset; |
132 |
+ |
r->hitf = rayhit; |
133 |
+ |
r->robj = OVOID; |
134 |
|
r->ro = NULL; |
135 |
< |
r->rot = FHUGE; |
135 |
> |
r->rox = NULL; |
136 |
> |
r->rt = r->rot = FHUGE; |
137 |
|
r->pert[0] = r->pert[1] = r->pert[2] = 0.0; |
138 |
+ |
r->uv[0] = r->uv[1] = 0.0; |
139 |
|
setcolor(r->pcol, 1.0, 1.0, 1.0); |
140 |
|
setcolor(r->rcol, 0.0, 0.0, 0.0); |
104 |
– |
r->rt = 0.0; |
141 |
|
} |
142 |
|
|
143 |
|
|
144 |
< |
raytrace(r) /* trace a ray and compute its value */ |
145 |
< |
RAY *r; |
144 |
> |
extern void |
145 |
> |
raytrace( /* trace a ray and compute its value */ |
146 |
> |
RAY *r |
147 |
> |
) |
148 |
|
{ |
111 |
– |
extern int (*trace)(); |
112 |
– |
int gotmat; |
113 |
– |
|
149 |
|
if (localhit(r, &thescene)) |
150 |
< |
gotmat = raycont(r); /* hit local surface, evaluate */ |
150 |
> |
raycont(r); /* hit local surface, evaluate */ |
151 |
|
else if (r->ro == &Aftplane) { |
152 |
|
r->ro = NULL; /* hit aft clipping plane */ |
153 |
|
r->rot = FHUGE; |
154 |
|
} else if (sourcehit(r)) |
155 |
< |
gotmat = rayshade(r, r->ro->omod); /* distant source */ |
155 |
> |
rayshade(r, r->ro->omod); /* distant source */ |
156 |
|
|
122 |
– |
if (r->ro != NULL && !gotmat) |
123 |
– |
objerror(r->ro, USER, "material not found"); |
124 |
– |
|
125 |
– |
rayparticipate(r); /* for participating medium */ |
126 |
– |
|
157 |
|
if (trace != NULL) |
158 |
|
(*trace)(r); /* trace execution */ |
159 |
+ |
|
160 |
+ |
rayparticipate(r); /* for participating medium */ |
161 |
|
} |
162 |
|
|
163 |
|
|
164 |
< |
raycont(r) /* check for clipped object and continue */ |
165 |
< |
register RAY *r; |
164 |
> |
extern void |
165 |
> |
raycont( /* check for clipped object and continue */ |
166 |
> |
register RAY *r |
167 |
> |
) |
168 |
|
{ |
169 |
|
if ((r->clipset != NULL && inset(r->clipset, r->ro->omod)) || |
170 |
< |
r->ro->omod == OVOID) { |
170 |
> |
!rayshade(r, r->ro->omod)) |
171 |
|
raytrans(r); |
138 |
– |
return(1); |
139 |
– |
} |
140 |
– |
return(rayshade(r, r->ro->omod)); |
172 |
|
} |
173 |
|
|
174 |
|
|
175 |
< |
raytrans(r) /* transmit ray as is */ |
176 |
< |
register RAY *r; |
175 |
> |
extern void |
176 |
> |
raytrans( /* transmit ray as is */ |
177 |
> |
register RAY *r |
178 |
> |
) |
179 |
|
{ |
180 |
|
RAY tr; |
181 |
|
|
182 |
< |
if (rayorigin(&tr, r, TRANS, 1.0) == 0) { |
182 |
> |
if (rayorigin(&tr, TRANS, r, NULL) == 0) { |
183 |
|
VCOPY(tr.rdir, r->rdir); |
184 |
|
rayvalue(&tr); |
185 |
|
copycolor(r->rcol, tr.rcol); |
188 |
|
} |
189 |
|
|
190 |
|
|
191 |
< |
rayshade(r, mod) /* shade ray r with material mod */ |
192 |
< |
register RAY *r; |
193 |
< |
int mod; |
191 |
> |
extern int |
192 |
> |
rayshade( /* shade ray r with material mod */ |
193 |
> |
register RAY *r, |
194 |
> |
int mod |
195 |
> |
) |
196 |
|
{ |
162 |
– |
static int depth = 0; |
163 |
– |
int gotmat; |
197 |
|
register OBJREC *m; |
198 |
< |
/* check for infinite loop */ |
166 |
< |
if (depth++ >= MAXLOOP) |
167 |
< |
objerror(r->ro, USER, "possible modifier loop"); |
198 |
> |
|
199 |
|
r->rt = r->rot; /* set effective ray length */ |
200 |
< |
for (gotmat = 0; !gotmat && mod != OVOID; mod = m->omod) { |
200 |
> |
for ( ; mod != OVOID; mod = m->omod) { |
201 |
|
m = objptr(mod); |
202 |
|
/****** unnecessary test since modifier() is always called |
203 |
|
if (!ismodifier(m->otype)) { |
206 |
|
} |
207 |
|
******/ |
208 |
|
/* hack for irradiance calculation */ |
209 |
< |
if (do_irrad && !(r->crtype & ~(PRIMARY|TRANS))) { |
209 |
> |
if (do_irrad && !(r->crtype & ~(PRIMARY|TRANS)) && |
210 |
> |
m->otype != MAT_CLIP && |
211 |
> |
(ofun[m->otype].flags & (T_M|T_X))) { |
212 |
|
if (irr_ignore(m->otype)) { |
180 |
– |
depth--; |
213 |
|
raytrans(r); |
214 |
|
return(1); |
215 |
|
} |
216 |
|
if (!islight(m->otype)) |
217 |
|
m = &Lamb; |
218 |
|
} |
219 |
< |
/* materials call raytexture */ |
220 |
< |
gotmat = (*ofun[m->otype].funp)(m, r); |
219 |
> |
if ((*ofun[m->otype].funp)(m, r)) |
220 |
> |
return(1); /* materials call raytexture() */ |
221 |
|
} |
222 |
< |
depth--; |
191 |
< |
return(gotmat); |
222 |
> |
return(0); /* no material! */ |
223 |
|
} |
224 |
|
|
225 |
|
|
226 |
< |
rayparticipate(r) /* compute ray medium participation */ |
227 |
< |
register RAY *r; |
226 |
> |
extern void |
227 |
> |
rayparticipate( /* compute ray medium participation */ |
228 |
> |
register RAY *r |
229 |
> |
) |
230 |
|
{ |
231 |
|
COLOR ce, ca; |
199 |
– |
double dist; |
232 |
|
double re, ge, be; |
233 |
|
|
234 |
|
if (intens(r->cext) <= 1./FHUGE) |
235 |
|
return; /* no medium */ |
236 |
< |
if ((dist = r->rot) >= FHUGE) |
237 |
< |
dist = 2.*thescene.cusize; /* what to use for infinity? */ |
238 |
< |
if (r->crtype & SHADOW) |
239 |
< |
dist *= 1. - salbedo; /* no scattering for sources */ |
240 |
< |
if (dist <= FTINY) |
241 |
< |
return; /* no effective ray travel */ |
242 |
< |
re = dist*colval(r->cext,RED); |
243 |
< |
ge = dist*colval(r->cext,GRN); |
244 |
< |
be = dist*colval(r->cext,BLU); |
245 |
< |
setcolor(ce, re>92. ? 0. : exp(-re), |
246 |
< |
ge>92. ? 0. : exp(-ge), |
247 |
< |
be>92. ? 0. : exp(-be)); |
248 |
< |
multcolor(r->rcol, ce); /* path absorption */ |
217 |
< |
if (r->albedo <= FTINY || r->crtype & SHADOW) |
236 |
> |
re = r->rot*colval(r->cext,RED); |
237 |
> |
ge = r->rot*colval(r->cext,GRN); |
238 |
> |
be = r->rot*colval(r->cext,BLU); |
239 |
> |
if (r->crtype & SHADOW) { /* no scattering for sources */ |
240 |
> |
re *= 1. - colval(r->albedo,RED); |
241 |
> |
ge *= 1. - colval(r->albedo,GRN); |
242 |
> |
be *= 1. - colval(r->albedo,BLU); |
243 |
> |
} |
244 |
> |
setcolor(ce, re<=FTINY ? 1. : re>92. ? 0. : exp(-re), |
245 |
> |
ge<=FTINY ? 1. : ge>92. ? 0. : exp(-ge), |
246 |
> |
be<=FTINY ? 1. : be>92. ? 0. : exp(-be)); |
247 |
> |
multcolor(r->rcol, ce); /* path extinction */ |
248 |
> |
if (r->crtype & SHADOW || intens(r->albedo) <= FTINY) |
249 |
|
return; /* no scattering */ |
250 |
< |
setcolor(ca, salbedo*colval(ambval,RED)*(1.-colval(ce,RED)), |
251 |
< |
salbedo*colval(ambval,GRN)*(1.-colval(ce,GRN)), |
252 |
< |
salbedo*colval(ambval,BLU)*(1.-colval(ce,BLU))); |
250 |
> |
setcolor(ca, |
251 |
> |
colval(r->albedo,RED)*colval(ambval,RED)*(1.-colval(ce,RED)), |
252 |
> |
colval(r->albedo,GRN)*colval(ambval,GRN)*(1.-colval(ce,GRN)), |
253 |
> |
colval(r->albedo,BLU)*colval(ambval,BLU)*(1.-colval(ce,BLU))); |
254 |
|
addcolor(r->rcol, ca); /* ambient in scattering */ |
255 |
|
srcscatter(r); /* source in scattering */ |
256 |
|
} |
257 |
|
|
258 |
|
|
259 |
< |
raytexture(r, mod) /* get material modifiers */ |
260 |
< |
RAY *r; |
261 |
< |
int mod; |
259 |
> |
extern void |
260 |
> |
raytexture( /* get material modifiers */ |
261 |
> |
RAY *r, |
262 |
> |
OBJECT mod |
263 |
> |
) |
264 |
|
{ |
231 |
– |
static int depth = 0; |
265 |
|
register OBJREC *m; |
233 |
– |
/* check for infinite loop */ |
234 |
– |
if (depth++ >= MAXLOOP) |
235 |
– |
objerror(r->ro, USER, "modifier loop"); |
266 |
|
/* execute textures and patterns */ |
267 |
|
for ( ; mod != OVOID; mod = m->omod) { |
268 |
|
m = objptr(mod); |
278 |
|
objerror(r->ro, USER, errmsg); |
279 |
|
} |
280 |
|
} |
251 |
– |
depth--; /* end here */ |
281 |
|
} |
282 |
|
|
283 |
|
|
284 |
< |
raymixture(r, fore, back, coef) /* mix modifiers */ |
285 |
< |
register RAY *r; |
286 |
< |
OBJECT fore, back; |
287 |
< |
double coef; |
284 |
> |
extern int |
285 |
> |
raymixture( /* mix modifiers */ |
286 |
> |
register RAY *r, |
287 |
> |
OBJECT fore, |
288 |
> |
OBJECT back, |
289 |
> |
double coef |
290 |
> |
) |
291 |
|
{ |
292 |
|
RAY fr, br; |
293 |
|
int foremat, backmat; |
294 |
|
register int i; |
295 |
< |
/* clip coefficient */ |
295 |
> |
/* bound coefficient */ |
296 |
|
if (coef > 1.0) |
297 |
|
coef = 1.0; |
298 |
|
else if (coef < 0.0) |
299 |
|
coef = 0.0; |
300 |
|
/* compute foreground and background */ |
301 |
< |
foremat = backmat = -1; |
301 |
> |
foremat = backmat = 0; |
302 |
|
/* foreground */ |
303 |
< |
copystruct(&fr, r); |
304 |
< |
if (fore != OVOID && coef > FTINY) |
303 |
> |
fr = *r; |
304 |
> |
if (coef > FTINY) |
305 |
|
foremat = rayshade(&fr, fore); |
306 |
|
/* background */ |
307 |
< |
copystruct(&br, r); |
308 |
< |
if (back != OVOID && coef < 1.0-FTINY) |
307 |
> |
br = *r; |
308 |
> |
if (coef < 1.0-FTINY) |
309 |
|
backmat = rayshade(&br, back); |
310 |
< |
/* check */ |
311 |
< |
if (foremat < 0) |
312 |
< |
if (backmat < 0) |
313 |
< |
foremat = backmat = 0; |
314 |
< |
else |
315 |
< |
foremat = backmat; |
316 |
< |
else if (backmat < 0) |
285 |
< |
backmat = foremat; |
286 |
< |
if ((foremat==0) != (backmat==0)) |
287 |
< |
objerror(r->ro, USER, "mixing material with non-material"); |
310 |
> |
/* check for transparency */ |
311 |
> |
if (backmat ^ foremat) { |
312 |
> |
if (backmat && coef > FTINY) |
313 |
> |
raytrans(&fr); |
314 |
> |
else if (foremat && coef < 1.0-FTINY) |
315 |
> |
raytrans(&br); |
316 |
> |
} |
317 |
|
/* mix perturbations */ |
318 |
|
for (i = 0; i < 3; i++) |
319 |
|
r->pert[i] = coef*fr.pert[i] + (1.0-coef)*br.pert[i]; |
322 |
|
scalecolor(br.pcol, 1.0-coef); |
323 |
|
copycolor(r->pcol, fr.pcol); |
324 |
|
addcolor(r->pcol, br.pcol); |
296 |
– |
/* mix returned ray values */ |
297 |
– |
if (foremat) { |
298 |
– |
scalecolor(fr.rcol, coef); |
299 |
– |
scalecolor(br.rcol, 1.0-coef); |
300 |
– |
copycolor(r->rcol, fr.rcol); |
301 |
– |
addcolor(r->rcol, br.rcol); |
302 |
– |
r->rt = bright(fr.rcol) > bright(br.rcol) ? fr.rt : br.rt; |
303 |
– |
} |
325 |
|
/* return value tells if material */ |
326 |
< |
return(foremat); |
326 |
> |
if (!foremat & !backmat) |
327 |
> |
return(0); |
328 |
> |
/* mix returned ray values */ |
329 |
> |
scalecolor(fr.rcol, coef); |
330 |
> |
scalecolor(br.rcol, 1.0-coef); |
331 |
> |
copycolor(r->rcol, fr.rcol); |
332 |
> |
addcolor(r->rcol, br.rcol); |
333 |
> |
r->rt = bright(fr.rcol) > bright(br.rcol) ? fr.rt : br.rt; |
334 |
> |
return(1); |
335 |
|
} |
336 |
|
|
337 |
|
|
338 |
< |
double |
339 |
< |
raydist(r, flags) /* compute (cumulative) ray distance */ |
340 |
< |
register RAY *r; |
341 |
< |
register int flags; |
338 |
> |
extern double |
339 |
> |
raydist( /* compute (cumulative) ray distance */ |
340 |
> |
register const RAY *r, |
341 |
> |
register int flags |
342 |
> |
) |
343 |
|
{ |
344 |
|
double sum = 0.0; |
345 |
|
|
351 |
|
} |
352 |
|
|
353 |
|
|
354 |
< |
double |
355 |
< |
raynormal(norm, r) /* compute perturbed normal for ray */ |
356 |
< |
FVECT norm; |
357 |
< |
register RAY *r; |
354 |
> |
extern void |
355 |
> |
raycontrib( /* compute (cumulative) ray contribution */ |
356 |
> |
double rc[3], |
357 |
> |
const RAY *r, |
358 |
> |
int flags |
359 |
> |
) |
360 |
|
{ |
361 |
+ |
double eext[3]; |
362 |
+ |
int i; |
363 |
+ |
|
364 |
+ |
eext[0] = eext[1] = eext[2] = 0.; |
365 |
+ |
rc[0] = rc[1] = rc[2] = 1.; |
366 |
+ |
|
367 |
+ |
while (r != NULL && r->crtype&flags) { |
368 |
+ |
for (i = 3; i--; ) { |
369 |
+ |
rc[i] *= colval(r->rcoef,i); |
370 |
+ |
eext[i] += r->rot * colval(r->cext,i); |
371 |
+ |
} |
372 |
+ |
r = r->parent; |
373 |
+ |
} |
374 |
+ |
for (i = 3; i--; ) |
375 |
+ |
rc[i] *= (eext[i] <= FTINY) ? 1. : |
376 |
+ |
(eext[i] > 92.) ? 0. : exp(-eext[i]); |
377 |
+ |
} |
378 |
+ |
|
379 |
+ |
|
380 |
+ |
extern double |
381 |
+ |
raynormal( /* compute perturbed normal for ray */ |
382 |
+ |
FVECT norm, |
383 |
+ |
register RAY *r |
384 |
+ |
) |
385 |
+ |
{ |
386 |
|
double newdot; |
387 |
|
register int i; |
388 |
|
|
413 |
|
} |
414 |
|
|
415 |
|
|
416 |
< |
newrayxf(r) /* get new tranformation matrix for ray */ |
417 |
< |
RAY *r; |
416 |
> |
extern void |
417 |
> |
newrayxf( /* get new tranformation matrix for ray */ |
418 |
> |
RAY *r |
419 |
> |
) |
420 |
|
{ |
421 |
|
static struct xfn { |
422 |
|
struct xfn *next; |
423 |
|
FULLXF xf; |
424 |
|
} xfseed = { &xfseed }, *xflast = &xfseed; |
425 |
|
register struct xfn *xp; |
426 |
< |
register RAY *rp; |
426 |
> |
register const RAY *rp; |
427 |
|
|
428 |
|
/* |
429 |
|
* Search for transform in circular list that |
434 |
|
if (rp->rox == &xp->xf) { /* xp in use */ |
435 |
|
xp = xp->next; /* move to next */ |
436 |
|
if (xp == xflast) { /* need new one */ |
437 |
< |
xp = (struct xfn *)bmalloc(sizeof(struct xfn)); |
437 |
> |
xp = (struct xfn *)malloc(sizeof(struct xfn)); |
438 |
|
if (xp == NULL) |
439 |
|
error(SYSTEM, |
440 |
|
"out of memory in newrayxf"); |
451 |
|
} |
452 |
|
|
453 |
|
|
454 |
< |
flipsurface(r) /* reverse surface orientation */ |
455 |
< |
register RAY *r; |
454 |
> |
extern void |
455 |
> |
flipsurface( /* reverse surface orientation */ |
456 |
> |
register RAY *r |
457 |
> |
) |
458 |
|
{ |
459 |
|
r->rod = -r->rod; |
460 |
|
r->ron[0] = -r->ron[0]; |
466 |
|
} |
467 |
|
|
468 |
|
|
469 |
< |
localhit(r, scene) /* check for hit in the octree */ |
470 |
< |
register RAY *r; |
471 |
< |
register CUBE *scene; |
469 |
> |
extern void |
470 |
> |
rayhit( /* standard ray hit test */ |
471 |
> |
OBJECT *oset, |
472 |
> |
RAY *r |
473 |
> |
) |
474 |
|
{ |
475 |
+ |
OBJREC *o; |
476 |
+ |
int i; |
477 |
+ |
|
478 |
+ |
for (i = oset[0]; i > 0; i--) { |
479 |
+ |
o = objptr(oset[i]); |
480 |
+ |
if ((*ofun[o->otype].funp)(o, r)) |
481 |
+ |
r->robj = oset[i]; |
482 |
+ |
} |
483 |
+ |
} |
484 |
+ |
|
485 |
+ |
|
486 |
+ |
extern int |
487 |
+ |
localhit( /* check for hit in the octree */ |
488 |
+ |
register RAY *r, |
489 |
+ |
register CUBE *scene |
490 |
+ |
) |
491 |
+ |
{ |
492 |
|
OBJECT cxset[MAXCSET+1]; /* set of checked objects */ |
493 |
|
FVECT curpos; /* current cube position */ |
494 |
|
int sflags; /* sign flags */ |
542 |
|
} |
543 |
|
cxset[0] = 0; |
544 |
|
raymove(curpos, cxset, sflags, r, scene); |
545 |
< |
return(r->ro != NULL & r->ro != &Aftplane); |
545 |
> |
return((r->ro != NULL) & (r->ro != &Aftplane)); |
546 |
|
} |
547 |
|
|
548 |
|
|
549 |
|
static int |
550 |
< |
raymove(pos, cxs, dirf, r, cu) /* check for hit as we move */ |
551 |
< |
FVECT pos; /* current position, modified herein */ |
552 |
< |
OBJECT *cxs; /* checked objects, modified by checkhit */ |
553 |
< |
int dirf; /* direction indicators to speed tests */ |
554 |
< |
register RAY *r; |
555 |
< |
register CUBE *cu; |
550 |
> |
raymove( /* check for hit as we move */ |
551 |
> |
FVECT pos, /* current position, modified herein */ |
552 |
> |
OBJECT *cxs, /* checked objects, modified by checkhit */ |
553 |
> |
int dirf, /* direction indicators to speed tests */ |
554 |
> |
register RAY *r, |
555 |
> |
register CUBE *cu |
556 |
> |
) |
557 |
|
{ |
558 |
|
int ax; |
559 |
|
double dt, t; |
633 |
|
} |
634 |
|
|
635 |
|
|
636 |
< |
static |
637 |
< |
checkhit(r, cu, cxs) /* check for hit in full cube */ |
638 |
< |
register RAY *r; |
639 |
< |
CUBE *cu; |
640 |
< |
OBJECT *cxs; |
636 |
> |
static int |
637 |
> |
checkhit( /* check for hit in full cube */ |
638 |
> |
register RAY *r, |
639 |
> |
CUBE *cu, |
640 |
> |
OBJECT *cxs |
641 |
> |
) |
642 |
|
{ |
643 |
|
OBJECT oset[MAXSET+1]; |
562 |
– |
register OBJREC *o; |
563 |
– |
register int i; |
644 |
|
|
645 |
|
objset(oset, cu->cutree); |
646 |
< |
checkset(oset, cxs); /* eliminate double-checking */ |
647 |
< |
for (i = oset[0]; i > 0; i--) { |
648 |
< |
o = objptr(oset[i]); |
649 |
< |
(*ofun[o->otype].funp)(o, r); |
650 |
< |
} |
571 |
< |
if (r->ro == NULL) |
646 |
> |
checkset(oset, cxs); /* avoid double-checking */ |
647 |
> |
|
648 |
> |
(*r->hitf)(oset, r); /* test for hit in set */ |
649 |
> |
|
650 |
> |
if (r->robj == OVOID) |
651 |
|
return(0); /* no scores yet */ |
652 |
|
|
653 |
|
return(incube(cu, r->rop)); /* hit OK if in current cube */ |
654 |
|
} |
655 |
|
|
656 |
|
|
657 |
< |
static |
658 |
< |
checkset(os, cs) /* modify checked set and set to check */ |
659 |
< |
register OBJECT *os; /* os' = os - cs */ |
660 |
< |
register OBJECT *cs; /* cs' = cs + os */ |
657 |
> |
static void |
658 |
> |
checkset( /* modify checked set and set to check */ |
659 |
> |
register OBJECT *os, /* os' = os - cs */ |
660 |
> |
register OBJECT *cs /* cs' = cs + os */ |
661 |
> |
) |
662 |
|
{ |
663 |
|
OBJECT cset[MAXCSET+MAXSET+1]; |
664 |
|
register int i, j; |