1 |
greg |
1.1 |
#ifndef lint |
2 |
schorsch |
2.5 |
static const char RCSid[] = "$Id: o_face.c,v 2.4 2003/03/11 17:08:55 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 |
schorsch |
2.5 |
extern int |
16 |
|
|
o_face( /* compute intersection with polygonal face */ |
17 |
|
|
OBJREC *o, |
18 |
|
|
register RAY *r |
19 |
|
|
) |
20 |
greg |
1.1 |
{ |
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 |
greg |
1.2 |
t = (DOT(r->rorg, f->norm) - f->offset) / rdot; |
44 |
greg |
1.1 |
|
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 |
greg |
1.3 |
if (!inface(pisect, f)) /* ray intersects face? */ |
52 |
|
|
return(0); |
53 |
greg |
1.1 |
|
54 |
greg |
1.3 |
r->ro = o; |
55 |
|
|
r->rot = t; |
56 |
|
|
VCOPY(r->rop, pisect); |
57 |
|
|
VCOPY(r->ron, f->norm); |
58 |
|
|
r->rod = rdot; |
59 |
greg |
2.4 |
r->pert[0] = r->pert[1] = r->pert[2] = 0.0; |
60 |
|
|
r->uv[0] = r->uv[1] = 0.0; |
61 |
greg |
1.4 |
r->rox = NULL; |
62 |
greg |
1.3 |
|
63 |
greg |
1.1 |
return(1); /* hit */ |
64 |
|
|
} |