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.7 by greg, Thu Apr 21 00:40:35 2016 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 + #ifndef STRICT
17 + #define STRICT  1
18 + #endif
19 +
20   #define  ROOT3          1.732050808
21  
22   /*
# Line 35 | Line 34 | static char SCCSid[] = "$SunId$ LBL";
34  
35   extern double  mincusize;               /* minimum cube size */
36  
37 + static int findcseg(FVECT ep0, FVECT ep1, CONE *co, FVECT p);
38  
39 < o_cone(o, cu)                   /* determine if cone intersects cube */
40 < OBJREC  *o;
41 < register CUBE  *cu;
39 >
40 >
41 > extern int
42 > o_cone(         /* determine if cone intersects cube */
43 >        OBJREC  *o,
44 >        CUBE  *cu
45 > )
46   {
43        double  dist2lseg(), findcseg();
47          CONE  *co;
48          FVECT  ep0, ep1;
49 + #if STRICT
50          FVECT  cumin, cumax;
51          CUBE  cukid;
52 +        int  j;
53 + #endif
54          double  r;
55          FVECT  p;
56 <        register int  i, j;
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 91 | Line 99 | register CUBE  *cu;
99   }
100  
101  
102 < double
103 < findcseg(ep0, ep1, co, p)       /* find line segment from cone closest to p */
104 < FVECT  ep0, ep1;
105 < register CONE  *co;
106 < FVECT  p;
102 > static int
103 > findcseg(       /* find line segment from cone closest to p */
104 >        FVECT  ep0,
105 >        FVECT  ep1,
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++)
105 <                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