| 1 |
greg |
1.1 |
/* Copyright (c) 1986 Regents of the University of California */
|
| 2 |
|
|
|
| 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 |
|
|
if (inface(pisect, f)) { /* ray intersects face? */
|
| 53 |
|
|
|
| 54 |
|
|
r->ro = o;
|
| 55 |
|
|
r->rot = t;
|
| 56 |
|
|
VCOPY(r->rop, pisect);
|
| 57 |
|
|
VCOPY(r->ron, f->norm);
|
| 58 |
|
|
r->rod = rdot;
|
| 59 |
|
|
}
|
| 60 |
|
|
return(1); /* hit */
|
| 61 |
|
|
}
|