ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/o_face.c
Revision: 2.1
Committed: Tue Nov 12 17:09:17 1991 UTC (32 years, 5 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.4: +0 -0 lines
Log Message:
updated revision number for release 2.0

File Contents

# Content
1 /* Copyright (c) 1990 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 t = (DOT(r->rorg, f->norm) - f->offset) / rdot;
45
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 return(0);
54
55 r->ro = o;
56 r->rot = t;
57 VCOPY(r->rop, pisect);
58 VCOPY(r->ron, f->norm);
59 r->rod = rdot;
60 r->rox = NULL;
61
62 return(1); /* hit */
63 }