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.4 by schorsch, Tue Mar 30 16:13:00 2004 UTC vs.
Revision 2.7 by greg, Thu Apr 21 00:40:35 2016 UTC

# Line 11 | Line 11 | static const char      RCSid[] = "$Id$";
11   #include  "octree.h"
12   #include  "object.h"
13   #include  "cone.h"
14 + #include  "plocate.h"
15  
16 + #ifndef STRICT
17 + #define STRICT  1
18 + #endif
19 +
20   #define  ROOT3          1.732050808
21  
22   /*
# Line 29 | Line 34 | static const char      RCSid[] = "$Id$";
34  
35   extern double  mincusize;               /* minimum cube size */
36  
37 < static double findcseg(FVECT ep0, FVECT ep1, CONE *co, FVECT p);
37 > static int findcseg(FVECT ep0, FVECT ep1, CONE *co, FVECT p);
38  
39  
40  
41   extern int
42   o_cone(         /* determine if cone intersects cube */
43          OBJREC  *o,
44 <        register CUBE  *cu
44 >        CUBE  *cu
45   )
46   {
47          CONE  *co;
48          FVECT  ep0, ep1;
49 < #ifdef STRICT
49 > #if STRICT
50          FVECT  cumin, cumax;
51          CUBE  cukid;
52 <        register int  j;
52 >        int  j;
53   #endif
54          double  r;
55          FVECT  p;
56 <        register int  i;
56 >        int  i;
57                                          /* get cone arguments */
58          co = getcone(o, 0);
59 +        if (co == NULL)                 /* check for degenerate case */
60 +                return(O_MISS);
61                                          /* get cube center */
62          r = cu->cusize * 0.5;
63          for (i = 0; i < 3; i++)
64                  p[i] = cu->cuorg[i] + r;
65          r *= ROOT3;                     /* bounding radius for cube */
66  
67 <        if (findcseg(ep0, ep1, co, p) > 0.0) {
67 >        if (findcseg(ep0, ep1, co, p)) {
68                                          /* check min. distance to cone */
69                  if (dist2lseg(p, ep0, ep1) > (r+FTINY)*(r+FTINY))
70                          return(O_MISS);
71 < #ifdef  STRICT
71 > #if  STRICT
72                                          /* get cube boundaries */
73                  for (i = 0; i < 3; i++)
74                          cumax[i] = (cumin[i] = cu->cuorg[i]) + cu->cusize;
# Line 92 | Line 99 | o_cone(                /* determine if cone intersects cube */
99   }
100  
101  
102 < static double
102 > static int
103   findcseg(       /* find line segment from cone closest to p */
104          FVECT  ep0,
105          FVECT  ep1,
106 <        register CONE  *co,
106 >        CONE  *co,
107          FVECT  p
108   )
109   {
110          double  d;
111          FVECT  v;
112 <        register int  i;
112 >        int  i;
113                                          /* find direction from axis to point */
114 <        for (i = 0; i < 3; i++)
108 <                v[i] = p[i] - CO_P0(co)[i];
114 >        VSUB(v, p, CO_P0(co));
115          d = DOT(v, co->ad);
116          for (i = 0; i < 3; i++)
117 <                v[i] = v[i] - d*co->ad[i];
118 <        d = normalize(v);
119 <        if (d > 0.0)                    /* find endpoints of segment */
120 <                for (i = 0; i < 3; i++) {
121 <                        ep0[i] = CO_R0(co)*v[i] + CO_P0(co)[i];
122 <                        ep1[i] = CO_R1(co)*v[i] + CO_P1(co)[i];
123 <                }
124 <        return(d);                      /* return distance from axis */
117 >                v[i] -= d*co->ad[i];
118 >        if (normalize(v) == 0.0)
119 >                return(0);
120 >                                        /* find endpoints of segment */
121 >        for (i = 0; i < 3; i++) {
122 >                ep0[i] = CO_R0(co)*v[i] + CO_P0(co)[i];
123 >                ep1[i] = CO_R1(co)*v[i] + CO_P1(co)[i];
124 >        }
125 >        return(1);                      /* return distance from axis */
126   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines