Back to index

radiance  4R0+20100331
o_face.c
Go to the documentation of this file.
00001 #ifndef lint
00002 static const char RCSid[] = "$Id: o_face.c,v 2.6 2006/03/02 16:51:55 greg Exp $";
00003 #endif
00004 /*
00005  *  o_face.c - compute ray intersection with faces.
00006  */
00007 
00008 #include "copyright.h"
00009 
00010 #include  "ray.h"
00011 #include  "face.h"
00012 #include  "rtotypes.h"
00013 
00014 
00015 extern int
00016 o_face(              /* compute intersection with polygonal face */
00017        OBJREC  *o,
00018        register RAY  *r
00019 )
00020 {
00021        double  rdot;        /* direction . normal */
00022        double  t;           /* distance to intersection */
00023        FVECT  pisect;              /* intersection point */
00024        register FACE  *f;   /* face record */
00025 
00026        f = getface(o);
00027               
00028        /*
00029         *  First, we find the distance to the plane containing the
00030         *  face.  If this distance is less than zero or greater
00031         *  than a previous intersection, we return.  Otherwise,
00032         *  we determine whether in fact the ray intersects the
00033         *  face.  The ray intersects the face if the
00034         *  point of intersection with the plane of the face
00035         *  is inside the face.
00036         */
00037                                           /* compute dist. to plane */
00038        rdot = -DOT(r->rdir, f->norm);
00039        if (rdot <= FTINY && rdot >= -FTINY)      /* ray parallels plane */
00040               t = FHUGE;
00041        else
00042               t = (DOT(r->rorg, f->norm) - f->offset) / rdot;
00043        
00044        if (t <= FTINY || t >= r->rot)            /* not good enough */
00045               return(0);
00046                                           /* compute intersection */
00047        VSUM(pisect, r->rorg, r->rdir, t);
00048 
00049        if (!inface(pisect, f))                   /* ray intersects face? */
00050               return(0);
00051 
00052        r->ro = o;
00053        r->rot = t;
00054        VCOPY(r->rop, pisect);
00055        VCOPY(r->ron, f->norm);
00056        r->rod = rdot;
00057        r->pert[0] = r->pert[1] = r->pert[2] = 0.0;
00058        r->uv[0] = r->uv[1] = 0.0;
00059        r->rox = NULL;
00060 
00061        return(1);                         /* hit */
00062 }