| 1 |
greg |
1.4 |
/* Copyright (c) 1990 Regents of the University of California */ |
| 2 |
greg |
1.1 |
|
| 3 |
|
|
#ifndef lint |
| 4 |
|
|
static char SCCSid[] = "$SunId$ LBL"; |
| 5 |
|
|
#endif |
| 6 |
|
|
|
| 7 |
|
|
/* |
| 8 |
|
|
* o_face.c - compute ray intersection with faces. |
| 9 |
|
|
* |
| 10 |
|
|
* 8/29/85 |
| 11 |
|
|
*/ |
| 12 |
|
|
|
| 13 |
|
|
#include "ray.h" |
| 14 |
|
|
|
| 15 |
|
|
#include "face.h" |
| 16 |
|
|
|
| 17 |
|
|
|
| 18 |
|
|
o_face(o, r) /* compute intersection with polygonal face */ |
| 19 |
|
|
OBJREC *o; |
| 20 |
|
|
register RAY *r; |
| 21 |
|
|
{ |
| 22 |
|
|
double rdot; /* direction . normal */ |
| 23 |
|
|
double t; /* distance to intersection */ |
| 24 |
|
|
FVECT pisect; /* intersection point */ |
| 25 |
|
|
register FACE *f; /* face record */ |
| 26 |
|
|
register int i; |
| 27 |
|
|
|
| 28 |
|
|
f = getface(o); |
| 29 |
|
|
|
| 30 |
|
|
/* |
| 31 |
|
|
* First, we find the distance to the plane containing the |
| 32 |
|
|
* face. If this distance is less than zero or greater |
| 33 |
|
|
* than a previous intersection, we return. Otherwise, |
| 34 |
|
|
* we determine whether in fact the ray intersects the |
| 35 |
|
|
* face. The ray intersects the face if the |
| 36 |
|
|
* point of intersection with the plane of the face |
| 37 |
|
|
* is inside the face. |
| 38 |
|
|
*/ |
| 39 |
|
|
/* compute dist. to plane */ |
| 40 |
|
|
rdot = -DOT(r->rdir, f->norm); |
| 41 |
|
|
if (rdot <= FTINY && rdot >= -FTINY) /* ray parallels plane */ |
| 42 |
|
|
t = FHUGE; |
| 43 |
|
|
else |
| 44 |
greg |
1.2 |
t = (DOT(r->rorg, f->norm) - f->offset) / rdot; |
| 45 |
greg |
1.1 |
|
| 46 |
|
|
if (t <= FTINY || t >= r->rot) /* not good enough */ |
| 47 |
|
|
return(0); |
| 48 |
|
|
/* compute intersection */ |
| 49 |
|
|
for (i = 0; i < 3; i++) |
| 50 |
|
|
pisect[i] = r->rorg[i] + r->rdir[i]*t; |
| 51 |
|
|
|
| 52 |
greg |
1.3 |
if (!inface(pisect, f)) /* ray intersects face? */ |
| 53 |
|
|
return(0); |
| 54 |
greg |
1.1 |
|
| 55 |
greg |
1.3 |
r->ro = o; |
| 56 |
|
|
r->rot = t; |
| 57 |
|
|
VCOPY(r->rop, pisect); |
| 58 |
|
|
VCOPY(r->ron, f->norm); |
| 59 |
|
|
r->rod = rdot; |
| 60 |
greg |
1.4 |
r->rox = NULL; |
| 61 |
greg |
1.3 |
|
| 62 |
greg |
1.1 |
return(1); /* hit */ |
| 63 |
|
|
} |