1 |
#ifndef lint |
2 |
static const char RCSid[] = "$Id: o_face.c,v 2.4 2003/03/11 17:08:55 greg Exp $"; |
3 |
#endif |
4 |
/* |
5 |
* o_face.c - compute ray intersection with faces. |
6 |
*/ |
7 |
|
8 |
#include "copyright.h" |
9 |
|
10 |
#include "ray.h" |
11 |
#include "face.h" |
12 |
#include "rtotypes.h" |
13 |
|
14 |
|
15 |
extern int |
16 |
o_face( /* compute intersection with polygonal face */ |
17 |
OBJREC *o, |
18 |
register RAY *r |
19 |
) |
20 |
{ |
21 |
double rdot; /* direction . normal */ |
22 |
double t; /* distance to intersection */ |
23 |
FVECT pisect; /* intersection point */ |
24 |
register FACE *f; /* face record */ |
25 |
register int i; |
26 |
|
27 |
f = getface(o); |
28 |
|
29 |
/* |
30 |
* First, we find the distance to the plane containing the |
31 |
* face. If this distance is less than zero or greater |
32 |
* than a previous intersection, we return. Otherwise, |
33 |
* we determine whether in fact the ray intersects the |
34 |
* face. The ray intersects the face if the |
35 |
* point of intersection with the plane of the face |
36 |
* is inside the face. |
37 |
*/ |
38 |
/* compute dist. to plane */ |
39 |
rdot = -DOT(r->rdir, f->norm); |
40 |
if (rdot <= FTINY && rdot >= -FTINY) /* ray parallels plane */ |
41 |
t = FHUGE; |
42 |
else |
43 |
t = (DOT(r->rorg, f->norm) - f->offset) / rdot; |
44 |
|
45 |
if (t <= FTINY || t >= r->rot) /* not good enough */ |
46 |
return(0); |
47 |
/* compute intersection */ |
48 |
for (i = 0; i < 3; i++) |
49 |
pisect[i] = r->rorg[i] + r->rdir[i]*t; |
50 |
|
51 |
if (!inface(pisect, f)) /* ray intersects face? */ |
52 |
return(0); |
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 |
r->pert[0] = r->pert[1] = r->pert[2] = 0.0; |
60 |
r->uv[0] = r->uv[1] = 0.0; |
61 |
r->rox = NULL; |
62 |
|
63 |
return(1); /* hit */ |
64 |
} |