| 1 |
greg |
1.1 |
#ifndef lint
|
| 2 |
greg |
2.8 |
static const char RCSid[] = "$Id: o_face.c,v 2.7 2014/07/08 18:25:00 greg Exp $";
|
| 3 |
greg |
1.1 |
#endif
|
| 4 |
|
|
/*
|
| 5 |
|
|
* o_face.c - compute ray intersection with faces.
|
| 6 |
greg |
2.2 |
*/
|
| 7 |
|
|
|
| 8 |
greg |
2.3 |
#include "copyright.h"
|
| 9 |
greg |
1.1 |
|
| 10 |
|
|
#include "ray.h"
|
| 11 |
|
|
#include "face.h"
|
| 12 |
schorsch |
2.5 |
#include "rtotypes.h"
|
| 13 |
greg |
1.1 |
|
| 14 |
|
|
|
| 15 |
greg |
2.7 |
int
|
| 16 |
schorsch |
2.5 |
o_face( /* compute intersection with polygonal face */
|
| 17 |
|
|
OBJREC *o,
|
| 18 |
greg |
2.7 |
RAY *r
|
| 19 |
schorsch |
2.5 |
)
|
| 20 |
greg |
1.1 |
{
|
| 21 |
|
|
double rdot; /* direction . normal */
|
| 22 |
|
|
double t; /* distance to intersection */
|
| 23 |
|
|
FVECT pisect; /* intersection point */
|
| 24 |
greg |
2.7 |
FACE *f; /* face record */
|
| 25 |
greg |
1.1 |
|
| 26 |
|
|
f = getface(o);
|
| 27 |
|
|
|
| 28 |
|
|
/*
|
| 29 |
|
|
* First, we find the distance to the plane containing the
|
| 30 |
greg |
2.8 |
* face. If the plane is parallel to our ray, or the
|
| 31 |
|
|
* previous hit was better, we return. Otherwise,
|
| 32 |
greg |
1.1 |
* we determine whether in fact the ray intersects the
|
| 33 |
|
|
* face. The ray intersects the face if the
|
| 34 |
|
|
* point of intersection with the plane of the face
|
| 35 |
|
|
* is inside the face.
|
| 36 |
|
|
*/
|
| 37 |
|
|
/* compute dist. to plane */
|
| 38 |
|
|
rdot = -DOT(r->rdir, f->norm);
|
| 39 |
greg |
2.8 |
if ((rdot <= FTINY) & (rdot >= -FTINY)) /* ray parallels plane */
|
| 40 |
|
|
return(0);
|
| 41 |
|
|
|
| 42 |
|
|
t = (DOT(r->rorg, f->norm) - f->offset) / rdot;
|
| 43 |
greg |
1.1 |
|
| 44 |
greg |
2.8 |
if (rayreject(o, r, t)) /* previous hit is better? */
|
| 45 |
greg |
1.1 |
return(0);
|
| 46 |
|
|
/* compute intersection */
|
| 47 |
greg |
2.6 |
VSUM(pisect, r->rorg, r->rdir, t);
|
| 48 |
greg |
1.1 |
|
| 49 |
greg |
1.3 |
if (!inface(pisect, f)) /* ray intersects face? */
|
| 50 |
|
|
return(0);
|
| 51 |
greg |
1.1 |
|
| 52 |
greg |
1.3 |
r->ro = o;
|
| 53 |
|
|
r->rot = t;
|
| 54 |
|
|
VCOPY(r->rop, pisect);
|
| 55 |
|
|
VCOPY(r->ron, f->norm);
|
| 56 |
|
|
r->rod = rdot;
|
| 57 |
greg |
2.4 |
r->pert[0] = r->pert[1] = r->pert[2] = 0.0;
|
| 58 |
|
|
r->uv[0] = r->uv[1] = 0.0;
|
| 59 |
greg |
1.4 |
r->rox = NULL;
|
| 60 |
greg |
1.3 |
|
| 61 |
greg |
1.1 |
return(1); /* hit */
|
| 62 |
|
|
}
|