| 18 |
|
|
| 19 |
|
#include "otspecial.h" |
| 20 |
|
|
| 21 |
+ |
#define MAXCSET ((MAXSET+1)*2-1) /* maximum check set size */ |
| 22 |
+ |
|
| 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 |
|
|
| 28 |
< |
long raynum = 0L; /* next unique ray number */ |
| 29 |
< |
long nrays = 0L; /* number of calls to localhit */ |
| 28 |
> |
unsigned long raynum = 0; /* next unique ray number */ |
| 29 |
> |
unsigned long nrays = 0; /* number of calls to localhit */ |
| 30 |
|
|
| 31 |
|
static FLOAT Lambfa[5] = {PI, PI, PI, 0.0, 0.0}; |
| 32 |
|
OBJREC Lamb = { |
| 34 |
|
{0, 5, NULL, Lambfa}, NULL, |
| 35 |
|
}; /* a Lambertian surface */ |
| 36 |
|
|
| 37 |
+ |
static int raymove(), checkset(), checkhit(); |
| 38 |
+ |
|
| 39 |
|
#define MAXLOOP 128 /* modifier loop detection */ |
| 40 |
|
|
| 41 |
|
#define RAYHIT (-1) /* return value for intercepted ray */ |
| 77 |
|
register RAY *r; |
| 78 |
|
{ |
| 79 |
|
r->rno = raynum++; |
| 76 |
– |
r->cxs[0] = 0; |
| 80 |
|
r->newcset = r->clipset; |
| 81 |
|
r->ro = NULL; |
| 82 |
|
r->rot = FHUGE; |
| 320 |
|
register RAY *r; |
| 321 |
|
register CUBE *scene; |
| 322 |
|
{ |
| 323 |
+ |
OBJECT cxset[MAXCSET+1]; /* set of checked objects */ |
| 324 |
|
FVECT curpos; /* current cube position */ |
| 325 |
|
int sflags; /* sign flags */ |
| 326 |
|
double t, dt; |
| 361 |
|
if (!incube(scene, curpos)) /* non-intersecting ray */ |
| 362 |
|
return(0); |
| 363 |
|
} |
| 364 |
< |
return(raymove(curpos, sflags, r, scene) == RAYHIT); |
| 364 |
> |
cxset[0] = 0; |
| 365 |
> |
return(raymove(curpos, cxset, sflags, r, scene) == RAYHIT); |
| 366 |
|
} |
| 367 |
|
|
| 368 |
|
|
| 369 |
|
static int |
| 370 |
< |
raymove(pos, dirf, r, cu) /* check for hit as we move */ |
| 371 |
< |
FVECT pos; /* modified */ |
| 370 |
> |
raymove(pos, cxs, dirf, r, cu) /* check for hit as we move */ |
| 371 |
> |
FVECT pos; /* current position, modified herein */ |
| 372 |
> |
OBJECT *cxs; /* checked objects, modified by checkhit */ |
| 373 |
|
int dirf; /* direction indicators to speed tests */ |
| 374 |
|
register RAY *r; |
| 375 |
|
register CUBE *cu; |
| 398 |
|
} |
| 399 |
|
for ( ; ; ) { |
| 400 |
|
cukid.cutree = octkid(cu->cutree, br); |
| 401 |
< |
if ((ax = raymove(pos,dirf,r,&cukid)) == RAYHIT) |
| 401 |
> |
if ((ax = raymove(pos,cxs,dirf,r,&cukid)) == RAYHIT) |
| 402 |
|
return(RAYHIT); |
| 403 |
|
sgn = 1 << ax; |
| 404 |
|
if (sgn & dirf) /* positive axis? */ |
| 417 |
|
} |
| 418 |
|
/*NOTREACHED*/ |
| 419 |
|
} |
| 420 |
< |
if (isfull(cu->cutree) && checkhit(r, cu)) |
| 420 |
> |
if (isfull(cu->cutree) && checkhit(r, cu, cxs)) |
| 421 |
|
return(RAYHIT); |
| 422 |
|
/* advance to next cube */ |
| 423 |
|
if (dirf&0x11) { |
| 450 |
|
|
| 451 |
|
|
| 452 |
|
static |
| 453 |
< |
checkhit(r, cu) /* check for hit in full cube */ |
| 453 |
> |
checkhit(r, cu, cxs) /* check for hit in full cube */ |
| 454 |
|
register RAY *r; |
| 455 |
|
CUBE *cu; |
| 456 |
+ |
OBJECT *cxs; |
| 457 |
|
{ |
| 458 |
|
OBJECT oset[MAXSET+1]; |
| 459 |
|
register OBJREC *o; |
| 460 |
|
register int i; |
| 461 |
|
|
| 462 |
|
objset(oset, cu->cutree); |
| 463 |
< |
checkset(oset, r->cxs); /* eliminate double-checking */ |
| 463 |
> |
checkset(oset, cxs); /* eliminate double-checking */ |
| 464 |
|
for (i = oset[0]; i > 0; i--) { |
| 465 |
|
o = objptr(oset[i]); |
| 466 |
+ |
if (o->omod == OVOID && issurface(o->otype)) |
| 467 |
+ |
continue; /* ignore void surfaces */ |
| 468 |
|
(*ofun[o->otype].funp)(o, r); |
| 469 |
|
} |
| 470 |
|
if (r->ro == NULL) |
| 476 |
|
|
| 477 |
|
static |
| 478 |
|
checkset(os, cs) /* modify checked set and set to check */ |
| 479 |
< |
register OBJECT os[MAXSET+1]; /* os' = os - cs */ |
| 480 |
< |
register OBJECT cs[MAXCSET+1]; /* cs' = cs + os */ |
| 479 |
> |
register OBJECT *os; /* os' = os - cs */ |
| 480 |
> |
register OBJECT *cs; /* cs' = cs + os */ |
| 481 |
|
{ |
| 482 |
|
OBJECT cset[MAXCSET+MAXSET+1]; |
| 483 |
< |
register int i, j, k; |
| 483 |
> |
register int i, j; |
| 484 |
> |
int k; |
| 485 |
|
/* copy os in place, cset <- cs */ |
| 486 |
|
cset[0] = 0; |
| 487 |
|
k = 0; |
| 493 |
|
cset[++cset[0]] = os[i]; |
| 494 |
|
} |
| 495 |
|
} |
| 496 |
+ |
if (!(os[0] = k)) /* new "to check" set size */ |
| 497 |
+ |
return; /* special case */ |
| 498 |
|
while (j <= cs[0]) /* get the rest of cs */ |
| 499 |
|
cset[++cset[0]] = cs[j++]; |
| 500 |
< |
if (cset[0] > MAXCSET) /* truncate if necessary */ |
| 500 |
> |
if (cset[0] > MAXCSET) /* truncate "checked" set if nec. */ |
| 501 |
|
cset[0] = MAXCSET; |
| 502 |
< |
setcopy(cs, cset); /* copy new "checked" set back */ |
| 503 |
< |
os[0] = k; /* new "to check" set size */ |
| 502 |
> |
/* setcopy(cs, cset); */ /* copy cset back to cs */ |
| 503 |
> |
os = cset; |
| 504 |
> |
for (i = os[0]; i-- >= 0; ) |
| 505 |
> |
*cs++ = *os++; |
| 506 |
|
} |