ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/ot/o_cone.c
(Generate patch)

Comparing ray/src/ot/o_cone.c (file contents):
Revision 2.1 by greg, Tue Nov 12 17:00:48 1991 UTC vs.
Revision 2.6 by greg, Wed Nov 21 18:51:04 2007 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1986 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   *  o_cone.c - routines for intersecting cubes with cones.
6   *
# Line 11 | Line 8 | static char SCCSid[] = "$SunId$ LBL";
8   */
9  
10   #include  "standard.h"
14
11   #include  "octree.h"
16
12   #include  "object.h"
18
13   #include  "cone.h"
14 + #include  "plocate.h"
15  
16   #define  ROOT3          1.732050808
17  
# Line 35 | Line 30 | static char SCCSid[] = "$SunId$ LBL";
30  
31   extern double  mincusize;               /* minimum cube size */
32  
33 + static int findcseg(FVECT ep0, FVECT ep1, CONE *co, FVECT p);
34  
35 < o_cone(o, cu)                   /* determine if cone intersects cube */
36 < OBJREC  *o;
37 < register CUBE  *cu;
35 >
36 >
37 > extern int
38 > o_cone(         /* determine if cone intersects cube */
39 >        OBJREC  *o,
40 >        register CUBE  *cu
41 > )
42   {
43        double  dist2lseg(), findcseg();
43          CONE  *co;
44          FVECT  ep0, ep1;
45 + #ifdef STRICT
46          FVECT  cumin, cumax;
47          CUBE  cukid;
48 +        register int  j;
49 + #endif
50          double  r;
51          FVECT  p;
52 <        register int  i, j;
52 >        register int  i;
53                                          /* get cone arguments */
54          co = getcone(o, 0);
55                                          /* get cube center */
# Line 56 | Line 58 | register CUBE  *cu;
58                  p[i] = cu->cuorg[i] + r;
59          r *= ROOT3;                     /* bounding radius for cube */
60  
61 <        if (findcseg(ep0, ep1, co, p) > 0.0) {
61 >        if (findcseg(ep0, ep1, co, p)) {
62                                          /* check min. distance to cone */
63                  if (dist2lseg(p, ep0, ep1) > (r+FTINY)*(r+FTINY))
64                          return(O_MISS);
# Line 91 | Line 93 | register CUBE  *cu;
93   }
94  
95  
96 < double
97 < findcseg(ep0, ep1, co, p)       /* find line segment from cone closest to p */
98 < FVECT  ep0, ep1;
99 < register CONE  *co;
100 < FVECT  p;
96 > static int
97 > findcseg(       /* find line segment from cone closest to p */
98 >        FVECT  ep0,
99 >        FVECT  ep1,
100 >        register CONE  *co,
101 >        FVECT  p
102 > )
103   {
104          double  d;
105          FVECT  v;
106          register int  i;
107                                          /* find direction from axis to point */
108 <        for (i = 0; i < 3; i++)
105 <                v[i] = p[i] - CO_P0(co)[i];
108 >        VSUB(v, p, CO_P0(co));
109          d = DOT(v, co->ad);
110          for (i = 0; i < 3; i++)
111 <                v[i] = v[i] - d*co->ad[i];
112 <        d = normalize(v);
113 <        if (d > 0.0)                    /* find endpoints of segment */
114 <                for (i = 0; i < 3; i++) {
115 <                        ep0[i] = CO_R0(co)*v[i] + CO_P0(co)[i];
116 <                        ep1[i] = CO_R1(co)*v[i] + CO_P1(co)[i];
117 <                }
118 <        return(d);                      /* return distance from axis */
111 >                v[i] -= d*co->ad[i];
112 >        if (normalize(v) == 0.0)
113 >                return(0);
114 >                                        /* find endpoints of segment */
115 >        for (i = 0; i < 3; i++) {
116 >                ep0[i] = CO_R0(co)*v[i] + CO_P0(co)[i];
117 >                ep1[i] = CO_R1(co)*v[i] + CO_P1(co)[i];
118 >        }
119 >        return(1);                      /* return distance from axis */
120   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines