1 |
< |
/* Copyright (c) 1986 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1990 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
59 |
|
r->pert[0] = r->pert[1] = r->pert[2] = 0.0; |
60 |
|
setcolor(r->pcol, 1.0, 1.0, 1.0); |
61 |
|
setcolor(r->rcol, 0.0, 0.0, 0.0); |
62 |
+ |
r->rt = 0.0; |
63 |
|
return(r->rlvl <= maxdepth && r->rweight >= minweight ? 0 : -1); |
64 |
|
} |
65 |
|
|
66 |
|
|
67 |
|
rayvalue(r) /* compute a ray's value */ |
68 |
< |
register RAY *r; |
68 |
> |
RAY *r; |
69 |
|
{ |
70 |
|
extern int (*trace)(); |
71 |
|
|
72 |
|
if (localhit(r, &thescene) || sourcehit(r)) |
73 |
< |
/* check for clipped object */ |
73 |
< |
if (r->clipset != NULL && inset(r->clipset, r->ro->omod)) |
74 |
< |
raytrans(r); |
75 |
< |
else |
76 |
< |
rayshade(r, r->ro->omod); |
73 |
> |
raycont(r); |
74 |
|
|
75 |
|
if (trace != NULL) |
76 |
|
(*trace)(r); /* trace execution */ |
77 |
|
} |
78 |
|
|
79 |
|
|
80 |
+ |
raycont(r) /* check for clipped object and continue */ |
81 |
+ |
register RAY *r; |
82 |
+ |
{ |
83 |
+ |
if (r->clipset != NULL && inset(r->clipset, r->ro->omod)) |
84 |
+ |
raytrans(r); |
85 |
+ |
else |
86 |
+ |
rayshade(r, r->ro->omod); |
87 |
+ |
} |
88 |
+ |
|
89 |
+ |
|
90 |
|
raytrans(r) /* transmit ray as is */ |
91 |
< |
RAY *r; |
91 |
> |
register RAY *r; |
92 |
|
{ |
93 |
|
RAY tr; |
94 |
|
|
96 |
|
VCOPY(tr.rdir, r->rdir); |
97 |
|
rayvalue(&tr); |
98 |
|
copycolor(r->rcol, tr.rcol); |
99 |
+ |
r->rt = r->rot + tr.rt; |
100 |
|
} |
101 |
|
} |
102 |
|
|
212 |
|
* still fraught with problems since reflected rays and similar |
213 |
|
* directions calculated from the surface normal may spawn rays behind |
214 |
|
* the surface. The only solution is to curb textures at high |
215 |
< |
* incidence (Rdot << 1). |
215 |
> |
* incidence (namely, keep DOT(rdir,pert) < Rdot). |
216 |
|
*/ |
217 |
|
|
218 |
|
for (i = 0; i < 3; i++) |
233 |
|
} |
234 |
|
|
235 |
|
|
236 |
+ |
newrayxf(r) /* get new tranformation matrix for ray */ |
237 |
+ |
RAY *r; |
238 |
+ |
{ |
239 |
+ |
static struct xfn { |
240 |
+ |
struct xfn *next; |
241 |
+ |
FULLXF xf; |
242 |
+ |
} xfseed = { &xfseed }, *xflast = &xfseed; |
243 |
+ |
register struct xfn *xp; |
244 |
+ |
register RAY *rp; |
245 |
+ |
|
246 |
+ |
/* |
247 |
+ |
* Search for transform in circular list that |
248 |
+ |
* has no associated ray in the tree. |
249 |
+ |
*/ |
250 |
+ |
xp = xflast; |
251 |
+ |
for (rp = r->parent; rp != NULL; rp = rp->parent) |
252 |
+ |
if (rp->rox == &xp->xf) { /* xp in use */ |
253 |
+ |
xp = xp->next; /* move to next */ |
254 |
+ |
if (xp == xflast) { /* need new one */ |
255 |
+ |
xp = (struct xfn *)bmalloc(sizeof(struct xfn)); |
256 |
+ |
if (xp == NULL) |
257 |
+ |
error(SYSTEM, |
258 |
+ |
"out of memory in newrayxf"); |
259 |
+ |
/* insert in list */ |
260 |
+ |
xp->next = xflast->next; |
261 |
+ |
xflast->next = xp; |
262 |
+ |
break; /* we're done */ |
263 |
+ |
} |
264 |
+ |
rp = r; /* start check over */ |
265 |
+ |
} |
266 |
+ |
/* got it */ |
267 |
+ |
r->rox = &xp->xf; |
268 |
+ |
xflast = xp; |
269 |
+ |
} |
270 |
+ |
|
271 |
+ |
|
272 |
|
flipsurface(r) /* reverse surface orientation */ |
273 |
|
register RAY *r; |
274 |
|
{ |
287 |
|
register CUBE *scene; |
288 |
|
{ |
289 |
|
FVECT curpos; /* current cube position */ |
290 |
< |
int mpos, mneg; /* sign flags */ |
290 |
> |
int sflags; /* sign flags */ |
291 |
|
double t, dt; |
292 |
|
register int i; |
293 |
|
|
294 |
|
nrays++; /* increment trace counter */ |
295 |
|
|
296 |
< |
mpos = mneg = 0; |
296 |
> |
sflags = 0; |
297 |
|
for (i = 0; i < 3; i++) { |
298 |
|
curpos[i] = r->rorg[i]; |
299 |
|
if (r->rdir[i] > FTINY) |
300 |
< |
mpos |= 1 << i; |
300 |
> |
sflags |= 1 << i; |
301 |
|
else if (r->rdir[i] < -FTINY) |
302 |
< |
mneg |= 1 << i; |
302 |
> |
sflags |= 0x10 << i; |
303 |
|
} |
304 |
|
t = 0.0; |
305 |
|
if (!incube(scene, curpos)) { |
306 |
|
/* find distance to entry */ |
307 |
|
for (i = 0; i < 3; i++) { |
308 |
|
/* plane in our direction */ |
309 |
< |
if (mpos & 1<<i) |
309 |
> |
if (sflags & 1<<i) |
310 |
|
dt = scene->cuorg[i]; |
311 |
< |
else if (mneg & 1<<i) |
311 |
> |
else if (sflags & 0x10<<i) |
312 |
|
dt = scene->cuorg[i] + scene->cusize; |
313 |
|
else |
314 |
|
continue; |
325 |
|
if (!incube(scene, curpos)) /* non-intersecting ray */ |
326 |
|
return(0); |
327 |
|
} |
328 |
< |
return(raymove(curpos, mpos, mneg, r, scene) == RAYHIT); |
328 |
> |
return(raymove(curpos, sflags, r, scene) == RAYHIT); |
329 |
|
} |
330 |
|
|
331 |
|
|
332 |
|
static int |
333 |
< |
raymove(pos, plus, minus, r, cu) /* check for hit as we move */ |
333 |
> |
raymove(pos, dirf, r, cu) /* check for hit as we move */ |
334 |
|
FVECT pos; /* modified */ |
335 |
< |
int plus, minus; /* direction indicators to speed tests */ |
335 |
> |
int dirf; /* direction indicators to speed tests */ |
336 |
|
register RAY *r; |
337 |
|
register CUBE *cu; |
338 |
|
{ |
339 |
|
int ax; |
340 |
|
double dt, t; |
297 |
– |
register int sgn; |
341 |
|
|
342 |
|
if (istree(cu->cutree)) { /* recurse on subcubes */ |
343 |
|
CUBE cukid; |
344 |
< |
register int br; |
344 |
> |
register int br, sgn; |
345 |
|
|
346 |
|
cukid.cusize = cu->cusize * 0.5; /* find subcube */ |
347 |
|
VCOPY(cukid.cuorg, cu->cuorg); |
360 |
|
} |
361 |
|
for ( ; ; ) { |
362 |
|
cukid.cutree = octkid(cu->cutree, br); |
363 |
< |
if ((ax = raymove(pos,plus,minus,r,&cukid)) == RAYHIT) |
363 |
> |
if ((ax = raymove(pos,dirf,r,&cukid)) == RAYHIT) |
364 |
|
return(RAYHIT); |
365 |
|
sgn = 1 << ax; |
366 |
< |
if (sgn & minus) /* negative axis? */ |
324 |
< |
if (sgn & br) { |
325 |
< |
cukid.cuorg[ax] -= cukid.cusize; |
326 |
< |
br &= ~sgn; |
327 |
< |
} else |
328 |
< |
return(ax); /* underflow */ |
329 |
< |
else |
366 |
> |
if (sgn & dirf) /* positive axis? */ |
367 |
|
if (sgn & br) |
368 |
|
return(ax); /* overflow */ |
369 |
|
else { |
370 |
|
cukid.cuorg[ax] += cukid.cusize; |
371 |
|
br |= sgn; |
372 |
|
} |
373 |
+ |
else |
374 |
+ |
if (sgn & br) { |
375 |
+ |
cukid.cuorg[ax] -= cukid.cusize; |
376 |
+ |
br &= ~sgn; |
377 |
+ |
} else |
378 |
+ |
return(ax); /* underflow */ |
379 |
|
} |
380 |
|
/*NOTREACHED*/ |
381 |
|
} |
382 |
|
if (isfull(cu->cutree) && checkhit(r, cu)) |
383 |
|
return(RAYHIT); |
384 |
|
/* advance to next cube */ |
385 |
< |
sgn = plus | minus; |
386 |
< |
if (sgn&1) { |
344 |
< |
dt = plus&1 ? cu->cuorg[0] + cu->cusize : cu->cuorg[0]; |
385 |
> |
if (dirf&0x11) { |
386 |
> |
dt = dirf&1 ? cu->cuorg[0] + cu->cusize : cu->cuorg[0]; |
387 |
|
t = (dt - pos[0])/r->rdir[0]; |
388 |
|
ax = 0; |
389 |
|
} else |
390 |
|
t = FHUGE; |
391 |
< |
if (sgn&2) { |
392 |
< |
dt = plus&2 ? cu->cuorg[1] + cu->cusize : cu->cuorg[1]; |
391 |
> |
if (dirf&0x22) { |
392 |
> |
dt = dirf&2 ? cu->cuorg[1] + cu->cusize : cu->cuorg[1]; |
393 |
|
dt = (dt - pos[1])/r->rdir[1]; |
394 |
|
if (dt < t) { |
395 |
|
t = dt; |
396 |
|
ax = 1; |
397 |
|
} |
398 |
|
} |
399 |
< |
if (sgn&4) { |
400 |
< |
dt = plus&4 ? cu->cuorg[2] + cu->cusize : cu->cuorg[2]; |
399 |
> |
if (dirf&0x44) { |
400 |
> |
dt = dirf&4 ? cu->cuorg[2] + cu->cusize : cu->cuorg[2]; |
401 |
|
dt = (dt - pos[2])/r->rdir[2]; |
402 |
|
if (dt < t) { |
403 |
|
t = dt; |