--- ray/src/ot/o_face.c 1989/02/02 10:33:03 1.1 +++ ray/src/ot/o_face.c 2004/03/27 12:41:45 2.4 @@ -1,9 +1,6 @@ -/* Copyright (c) 1986 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: o_face.c,v 2.4 2004/03/27 12:41:45 schorsch Exp $"; #endif - /* * o_face.c - routines for creating octrees for polygonal faces. * @@ -40,10 +37,12 @@ static char SCCSid[] = "$SunId$ LBL"; * 5) If test 4 fails, we have no intersection. */ - -o_face(o, cu) /* determine if face intersects cube */ -OBJREC *o; -CUBE *cu; +/* XXX this is extern, but not declared in any header file yet */ +int +o_face( /* determine if face intersects cube */ + OBJREC *o, + CUBE *cu +) { FVECT cumin, cumax; FVECT v1, v2; @@ -54,20 +53,21 @@ CUBE *cu; /* get face arguments */ f = getface(o); if (f->area == 0.0) /* empty face */ - return(0); + return(O_MISS); /* compute cube boundaries */ for (j = 0; j < 3; j++) - cumax[j] = (cumin[j] = cu->cuorg[j]) + cu->cusize; + cumax[j] = (cumin[j] = cu->cuorg[j]-FTINY) + + cu->cusize + 2.0*FTINY; vloc = ABOVE | BELOW; /* check vertices */ for (i = 0; i < f->nv; i++) - if (j = plocate(VERTEX(f,i), cumin, cumax)) + if ( (j = plocate(VERTEX(f,i), cumin, cumax)) ) vloc &= j; else - return(1); /* vertex inside */ + return(O_HIT); /* vertex inside */ if (vloc) /* all to one side */ - return(0); + return(O_MISS); for (i = 0; i < f->nv; i++) { /* check edges */ if ((j = i + 1) >= f->nv) @@ -75,7 +75,7 @@ CUBE *cu; VCOPY(v1, VERTEX(f,i)); /* clip modifies */ VCOPY(v2, VERTEX(f,j)); /* the vertices! */ if (clip(v1, v2, cumin, cumax)) - return(1); /* edge inside */ + return(O_HIT); /* edge inside */ } /* see if cube cuts plane */ for (j = 0; j < 3; j++) @@ -86,15 +86,15 @@ CUBE *cu; v1[j] = cumax[j]; v2[j] = cumin[j]; } - if ((d1 = DOT(v1, f->norm) - f->const) > FTINY) - return(0); - if ((d2 = DOT(v2, f->norm) - f->const) < -FTINY) - return(0); + if ((d1 = DOT(v1, f->norm) - f->offset) > FTINY) + return(O_MISS); + if ((d2 = DOT(v2, f->norm) - f->offset) < -FTINY) + return(O_MISS); /* intersect face */ for (j = 0; j < 3; j++) v1[j] = (v1[j]*d2 - v2[j]*d1)/(d2 - d1); if (inface(v1, f)) - return(1); + return(O_HIT); - return(0); /* no intersection */ + return(O_MISS); /* no intersection */ }