--- ray/src/rt/raytrace.c 1994/12/20 20:18:22 2.16 +++ ray/src/rt/raytrace.c 1995/09/29 10:46:12 2.20 @@ -1,4 +1,4 @@ -/* Copyright (c) 1994 Regents of the University of California */ +/* Copyright (c) 1995 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -34,7 +34,7 @@ OBJREC Lamb = { {0, 5, NULL, Lambfa}, NULL, }; /* a Lambertian surface */ -static OBJREC Aftplane; /* aft clipping plane object */ +OBJREC Aftplane; /* aft clipping plane object */ static int raymove(), checkset(), checkhit(); @@ -81,16 +81,8 @@ register RAY *r; { r->rno = raynum++; r->newcset = r->clipset; - if (r->rmax > FTINY) { - r->ro = &Aftplane; - r->rot = r->rmax; - r->rop[0] = r->rorg[0] + r->rot*r->rdir[0]; - r->rop[1] = r->rorg[1] + r->rot*r->rdir[1]; - r->rop[2] = r->rorg[2] + r->rot*r->rdir[2]; - } else { - r->ro = NULL; - r->rot = FHUGE; - } + r->ro = NULL; + r->rot = FHUGE; r->pert[0] = r->pert[1] = r->pert[2] = 0.0; setcolor(r->pcol, 1.0, 1.0, 1.0); setcolor(r->rcol, 0.0, 0.0, 0.0); @@ -139,6 +131,8 @@ register RAY *r; if (rayorigin(&tr, r, TRANS, 1.0) == 0) { VCOPY(tr.rdir, r->rdir); + if (r->rmax > FTINY) + tr.rmax = r->rmax - r->rot; rayvalue(&tr); copycolor(r->rcol, tr.rcol); r->rt = r->rot + tr.rt; @@ -201,8 +195,11 @@ int mod; error(USER, errmsg); } ******/ - if ((*ofun[m->otype].funp)(m, r)) - objerror(r->ro, USER, "conflicting materials"); + if ((*ofun[m->otype].funp)(m, r)) { + sprintf(errmsg, "conflicting material \"%s\"", + m->oname); + objerror(r->ro, USER, errmsg); + } } depth--; /* end here */ } @@ -367,6 +364,14 @@ register CUBE *scene; } if (sflags == 0) error(CONSISTENCY, "zero ray direction in localhit"); + /* start off assuming nothing hit */ + if (r->rmax > FTINY) { /* except aft plane if one */ + r->ro = &Aftplane; + r->rot = r->rmax; + for (i = 0; i < 3; i++) + r->rop[i] = r->rorg[i] + r->rot*r->rdir[i]; + } + /* find global cube entrance point */ t = 0.0; if (!incube(scene, curpos)) { /* find distance to entry */ @@ -384,6 +389,8 @@ register CUBE *scene; t = dt; /* farthest face is the one */ } t += FTINY; /* fudge to get inside cube */ + if (t >= r->rot) /* clipped already */ + return(0); /* advance position */ for (i = 0; i < 3; i++) curpos[i] += r->rdir[i]*t; @@ -392,8 +399,8 @@ register CUBE *scene; return(0); } cxset[0] = 0; - return(raymove(curpos, cxset, sflags, r, scene) == RAYHIT && - r->ro != &Aftplane); + raymove(curpos, cxset, sflags, r, scene); + return(r->ro != NULL & r->ro != &Aftplane); } @@ -448,7 +455,10 @@ register CUBE *cu; } /*NOTREACHED*/ } - if (isfull(cu->cutree) && checkhit(r, cu, cxs)) + if (isfull(cu->cutree)) { + if (checkhit(r, cu, cxs)) + return(RAYHIT); + } else if (r->ro == &Aftplane && incube(cu, r->rop)) return(RAYHIT); /* advance to next cube */ if (dirf&0x11) {