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

# User Rev Content
1 greg 1.1 #ifndef lint
2 greg 2.2 static const char RCSid[] = "$Id$";
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    
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 greg 1.2 t = (DOT(r->rorg, f->norm) - f->offset) / rdot;
42 greg 1.1
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 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 1.4 r->rox = NULL;
58 greg 1.3
59 greg 1.1 return(1); /* hit */
60     }