251 |
|
register CUBE *scene; |
252 |
|
{ |
253 |
|
FVECT curpos; /* current cube position */ |
254 |
< |
int mpos, mneg; /* sign flags */ |
254 |
> |
int sflags; /* sign flags */ |
255 |
|
double t, dt; |
256 |
|
register int i; |
257 |
|
|
258 |
|
nrays++; /* increment trace counter */ |
259 |
|
|
260 |
< |
mpos = mneg = 0; |
260 |
> |
sflags = 0; |
261 |
|
for (i = 0; i < 3; i++) { |
262 |
|
curpos[i] = r->rorg[i]; |
263 |
|
if (r->rdir[i] > FTINY) |
264 |
< |
mpos |= 1 << i; |
264 |
> |
sflags |= 1 << i; |
265 |
|
else if (r->rdir[i] < -FTINY) |
266 |
< |
mneg |= 1 << i; |
266 |
> |
sflags |= 0x10 << i; |
267 |
|
} |
268 |
|
t = 0.0; |
269 |
|
if (!incube(scene, curpos)) { |
270 |
|
/* find distance to entry */ |
271 |
|
for (i = 0; i < 3; i++) { |
272 |
|
/* plane in our direction */ |
273 |
< |
if (mpos & 1<<i) |
273 |
> |
if (sflags & 1<<i) |
274 |
|
dt = scene->cuorg[i]; |
275 |
< |
else if (mneg & 1<<i) |
275 |
> |
else if (sflags & 0x10<<i) |
276 |
|
dt = scene->cuorg[i] + scene->cusize; |
277 |
|
else |
278 |
|
continue; |
289 |
|
if (!incube(scene, curpos)) /* non-intersecting ray */ |
290 |
|
return(0); |
291 |
|
} |
292 |
< |
return(raymove(curpos, mpos, mneg, r, scene) == RAYHIT); |
292 |
> |
return(raymove(curpos, sflags, r, scene) == RAYHIT); |
293 |
|
} |
294 |
|
|
295 |
|
|
296 |
|
static int |
297 |
< |
raymove(pos, plus, minus, r, cu) /* check for hit as we move */ |
297 |
> |
raymove(pos, dirf, r, cu) /* check for hit as we move */ |
298 |
|
FVECT pos; /* modified */ |
299 |
< |
int plus, minus; /* direction indicators to speed tests */ |
299 |
> |
int dirf; /* direction indicators to speed tests */ |
300 |
|
register RAY *r; |
301 |
|
register CUBE *cu; |
302 |
|
{ |
303 |
|
int ax; |
304 |
|
double dt, t; |
305 |
– |
register int sgn; |
305 |
|
|
306 |
|
if (istree(cu->cutree)) { /* recurse on subcubes */ |
307 |
|
CUBE cukid; |
308 |
< |
register int br; |
308 |
> |
register int br, sgn; |
309 |
|
|
310 |
|
cukid.cusize = cu->cusize * 0.5; /* find subcube */ |
311 |
|
VCOPY(cukid.cuorg, cu->cuorg); |
324 |
|
} |
325 |
|
for ( ; ; ) { |
326 |
|
cukid.cutree = octkid(cu->cutree, br); |
327 |
< |
if ((ax = raymove(pos,plus,minus,r,&cukid)) == RAYHIT) |
327 |
> |
if ((ax = raymove(pos,dirf,r,&cukid)) == RAYHIT) |
328 |
|
return(RAYHIT); |
329 |
|
sgn = 1 << ax; |
330 |
< |
if (sgn & minus) /* negative axis? */ |
332 |
< |
if (sgn & br) { |
333 |
< |
cukid.cuorg[ax] -= cukid.cusize; |
334 |
< |
br &= ~sgn; |
335 |
< |
} else |
336 |
< |
return(ax); /* underflow */ |
337 |
< |
else |
330 |
> |
if (sgn & dirf) /* positive axis? */ |
331 |
|
if (sgn & br) |
332 |
|
return(ax); /* overflow */ |
333 |
|
else { |
334 |
|
cukid.cuorg[ax] += cukid.cusize; |
335 |
|
br |= sgn; |
336 |
|
} |
337 |
+ |
else |
338 |
+ |
if (sgn & br) { |
339 |
+ |
cukid.cuorg[ax] -= cukid.cusize; |
340 |
+ |
br &= ~sgn; |
341 |
+ |
} else |
342 |
+ |
return(ax); /* underflow */ |
343 |
|
} |
344 |
|
/*NOTREACHED*/ |
345 |
|
} |
346 |
|
if (isfull(cu->cutree) && checkhit(r, cu)) |
347 |
|
return(RAYHIT); |
348 |
|
/* advance to next cube */ |
349 |
< |
sgn = plus | minus; |
350 |
< |
if (sgn&1) { |
352 |
< |
dt = plus&1 ? cu->cuorg[0] + cu->cusize : cu->cuorg[0]; |
349 |
> |
if (dirf&0x11) { |
350 |
> |
dt = dirf&1 ? cu->cuorg[0] + cu->cusize : cu->cuorg[0]; |
351 |
|
t = (dt - pos[0])/r->rdir[0]; |
352 |
|
ax = 0; |
353 |
|
} else |
354 |
|
t = FHUGE; |
355 |
< |
if (sgn&2) { |
356 |
< |
dt = plus&2 ? cu->cuorg[1] + cu->cusize : cu->cuorg[1]; |
355 |
> |
if (dirf&0x22) { |
356 |
> |
dt = dirf&2 ? cu->cuorg[1] + cu->cusize : cu->cuorg[1]; |
357 |
|
dt = (dt - pos[1])/r->rdir[1]; |
358 |
|
if (dt < t) { |
359 |
|
t = dt; |
360 |
|
ax = 1; |
361 |
|
} |
362 |
|
} |
363 |
< |
if (sgn&4) { |
364 |
< |
dt = plus&4 ? cu->cuorg[2] + cu->cusize : cu->cuorg[2]; |
363 |
> |
if (dirf&0x44) { |
364 |
> |
dt = dirf&4 ? cu->cuorg[2] + cu->cusize : cu->cuorg[2]; |
365 |
|
dt = (dt - pos[2])/r->rdir[2]; |
366 |
|
if (dt < t) { |
367 |
|
t = dt; |