| 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 */ |
| 28 |
|
long raynum = 0L; /* next unique ray number */ |
| 29 |
|
long nrays = 0L; /* number of calls to localhit */ |
| 30 |
|
|
| 31 |
< |
static double Lambfa[5] = {PI, PI, PI, 0.0, 0.0}; |
| 31 |
> |
static FLOAT Lambfa[5] = {PI, PI, PI, 0.0, 0.0}; |
| 32 |
|
OBJREC Lamb = { |
| 33 |
|
OVOID, MAT_PLASTIC, "Lambertian", |
| 34 |
< |
{0, 5, NULL, Lambfa}, NULL, -1, |
| 34 |
> |
{0, 5, NULL, Lambfa}, NULL, |
| 35 |
|
}; /* a Lambertian surface */ |
| 36 |
|
|
| 37 |
|
#define MAXLOOP 128 /* modifier loop detection */ |
| 153 |
|
m = &Lamb; |
| 154 |
|
} |
| 155 |
|
(*ofun[m->otype].funp)(m, r); /* execute function */ |
| 154 |
– |
m->lastrno = r->rno; |
| 156 |
|
if (ismaterial(m->otype)) { /* materials call raytexture */ |
| 157 |
|
depth--; |
| 158 |
|
return; /* we're done */ |
| 179 |
|
error(USER, errmsg); |
| 180 |
|
} |
| 181 |
|
(*ofun[m->otype].funp)(m, r); |
| 181 |
– |
m->lastrno = r->rno; |
| 182 |
|
} |
| 183 |
|
depth--; /* end here */ |
| 184 |
|
} |
| 318 |
|
register RAY *r; |
| 319 |
|
register CUBE *scene; |
| 320 |
|
{ |
| 321 |
+ |
OBJECT cxset[MAXCSET+1]; /* set of checked objects */ |
| 322 |
|
FVECT curpos; /* current cube position */ |
| 323 |
|
int sflags; /* sign flags */ |
| 324 |
|
double t, dt; |
| 359 |
|
if (!incube(scene, curpos)) /* non-intersecting ray */ |
| 360 |
|
return(0); |
| 361 |
|
} |
| 362 |
< |
return(raymove(curpos, sflags, r, scene) == RAYHIT); |
| 362 |
> |
cxset[0] = 0; |
| 363 |
> |
return(raymove(curpos, cxset, sflags, r, scene) == RAYHIT); |
| 364 |
|
} |
| 365 |
|
|
| 366 |
|
|
| 367 |
|
static int |
| 368 |
< |
raymove(pos, dirf, r, cu) /* check for hit as we move */ |
| 369 |
< |
FVECT pos; /* modified */ |
| 368 |
> |
raymove(pos, cxs, dirf, r, cu) /* check for hit as we move */ |
| 369 |
> |
FVECT pos; /* current position, modified herein */ |
| 370 |
> |
OBJECT *cxs; /* checked objects, modified by checkhit */ |
| 371 |
|
int dirf; /* direction indicators to speed tests */ |
| 372 |
|
register RAY *r; |
| 373 |
|
register CUBE *cu; |
| 396 |
|
} |
| 397 |
|
for ( ; ; ) { |
| 398 |
|
cukid.cutree = octkid(cu->cutree, br); |
| 399 |
< |
if ((ax = raymove(pos,dirf,r,&cukid)) == RAYHIT) |
| 399 |
> |
if ((ax = raymove(pos,cxs,dirf,r,&cukid)) == RAYHIT) |
| 400 |
|
return(RAYHIT); |
| 401 |
|
sgn = 1 << ax; |
| 402 |
|
if (sgn & dirf) /* positive axis? */ |
| 415 |
|
} |
| 416 |
|
/*NOTREACHED*/ |
| 417 |
|
} |
| 418 |
< |
if (isfull(cu->cutree) && checkhit(r, cu)) |
| 418 |
> |
if (isfull(cu->cutree) && checkhit(r, cu, cxs)) |
| 419 |
|
return(RAYHIT); |
| 420 |
|
/* advance to next cube */ |
| 421 |
|
if (dirf&0x11) { |
| 448 |
|
|
| 449 |
|
|
| 450 |
|
static |
| 451 |
< |
checkhit(r, cu) /* check for hit in full cube */ |
| 451 |
> |
checkhit(r, cu, cxs) /* check for hit in full cube */ |
| 452 |
|
register RAY *r; |
| 453 |
|
CUBE *cu; |
| 454 |
+ |
OBJECT *cxs; |
| 455 |
|
{ |
| 456 |
|
OBJECT oset[MAXSET+1]; |
| 457 |
|
register OBJREC *o; |
| 458 |
|
register int i; |
| 459 |
|
|
| 460 |
|
objset(oset, cu->cutree); |
| 461 |
+ |
checkset(oset, cxs); /* eliminate double-checking */ |
| 462 |
|
for (i = oset[0]; i > 0; i--) { |
| 463 |
|
o = objptr(oset[i]); |
| 464 |
< |
if (o->lastrno == r->rno) /* checked already? */ |
| 465 |
< |
continue; |
| 464 |
> |
if (o->omod == OVOID && issurface(o->otype)) |
| 465 |
> |
continue; /* ignore void surfaces */ |
| 466 |
|
(*ofun[o->otype].funp)(o, r); |
| 462 |
– |
o->lastrno = r->rno; |
| 467 |
|
} |
| 468 |
|
if (r->ro == NULL) |
| 469 |
|
return(0); /* no scores yet */ |
| 470 |
|
|
| 471 |
|
return(incube(cu, r->rop)); /* hit OK if in current cube */ |
| 472 |
+ |
} |
| 473 |
+ |
|
| 474 |
+ |
|
| 475 |
+ |
static |
| 476 |
+ |
checkset(os, cs) /* modify checked set and set to check */ |
| 477 |
+ |
register OBJECT *os; /* os' = os - cs */ |
| 478 |
+ |
register OBJECT *cs; /* cs' = cs + os */ |
| 479 |
+ |
{ |
| 480 |
+ |
OBJECT cset[MAXCSET+MAXSET+1]; |
| 481 |
+ |
register int i, j; |
| 482 |
+ |
int k; |
| 483 |
+ |
/* copy os in place, cset <- cs */ |
| 484 |
+ |
cset[0] = 0; |
| 485 |
+ |
k = 0; |
| 486 |
+ |
for (i = j = 1; i <= os[0]; i++) { |
| 487 |
+ |
while (j <= cs[0] && cs[j] < os[i]) |
| 488 |
+ |
cset[++cset[0]] = cs[j++]; |
| 489 |
+ |
if (j > cs[0] || os[i] != cs[j]) { /* object to check */ |
| 490 |
+ |
os[++k] = os[i]; |
| 491 |
+ |
cset[++cset[0]] = os[i]; |
| 492 |
+ |
} |
| 493 |
+ |
} |
| 494 |
+ |
if (!(os[0] = k)) /* new "to check" set size */ |
| 495 |
+ |
return; /* special case */ |
| 496 |
+ |
while (j <= cs[0]) /* get the rest of cs */ |
| 497 |
+ |
cset[++cset[0]] = cs[j++]; |
| 498 |
+ |
if (cset[0] > MAXCSET) /* truncate "checked" set if nec. */ |
| 499 |
+ |
cset[0] = MAXCSET; |
| 500 |
+ |
/* setcopy(cs, cset); */ /* copy cset back to cs */ |
| 501 |
+ |
os = cset; |
| 502 |
+ |
for (i = os[0]; i-- >= 0; ) |
| 503 |
+ |
*cs++ = *os++; |
| 504 |
|
} |