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