ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/o_face.c
Revision: 2.3
Committed: Tue Feb 25 02:47:23 2003 UTC (21 years, 2 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.2: +1 -56 lines
Log Message:
Replaced inline copyright notice with #include "copyright.h"

File Contents

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