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

Comparing ray/src/common/fvect.c (file contents):
Revision 2.7 by greg, Tue Feb 25 02:47:21 2003 UTC vs.
Revision 2.12 by greg, Sun Sep 26 15:42:48 2010 UTC

# Line 12 | Line 12 | static const char      RCSid[] = "$Id$";
12  
13  
14   double
15 < fdot(v1, v2)                    /* return the dot product of two vectors */
16 < register FVECT  v1, v2;
15 > fdot(                           /* return the dot product of two vectors */
16 > FVECT v1,
17 > FVECT v2
18 > )
19   {
20          return(DOT(v1,v2));
21   }
22  
23  
24   double
25 < dist2(p1, p2)                   /* return square of distance between points */
26 < register FVECT  p1, p2;
25 > dist2(                          /* return square of distance between points */
26 > FVECT p1,
27 > FVECT p2
28 > )
29   {
30          FVECT  delta;
31  
# Line 34 | Line 38 | register FVECT  p1, p2;
38  
39  
40   double
41 < dist2line(p, ep1, ep2)          /* return square of distance to line */
42 < FVECT  p;               /* the point */
43 < FVECT  ep1, ep2;        /* points on the line */
41 > dist2line(                      /* return square of distance to line */
42 > FVECT p,                /* the point */
43 > FVECT ep1,
44 > FVECT ep2               /* points on the line */
45 > )
46   {
47 <        register double  d, d1, d2;
47 >        double  d, d1, d2;
48  
49          d = dist2(ep1, ep2);
50          d1 = dist2(ep1, p);
# Line 49 | Line 55 | FVECT  ep1, ep2;       /* points on the line */
55  
56  
57   double
58 < dist2lseg(p, ep1, ep2)          /* return square of distance to line segment */
59 < FVECT  p;               /* the point */
60 < FVECT  ep1, ep2;        /* the end points */
58 > dist2lseg(                      /* return square of distance to line segment */
59 > FVECT p,                /* the point */
60 > FVECT ep1,
61 > FVECT ep2               /* the end points */
62 > )
63   {
64 <        register double  d, d1, d2;
64 >        double  d, d1, d2;
65  
66          d = dist2(ep1, ep2);
67          d1 = dist2(ep1, p);
# Line 73 | Line 81 | FVECT  ep1, ep2;       /* the end points */
81  
82  
83   void
84 < fcross(vres, v1, v2)            /* vres = v1 X v2 */
85 < register FVECT  vres, v1, v2;
84 > fcross(                         /* vres = v1 X v2 */
85 > FVECT vres,
86 > FVECT v1,
87 > FVECT v2
88 > )
89   {
90          vres[0] = v1[1]*v2[2] - v1[2]*v2[1];
91          vres[1] = v1[2]*v2[0] - v1[0]*v2[2];
# Line 83 | Line 94 | register FVECT  vres, v1, v2;
94  
95  
96   void
97 < fvsum(vres, v0, v1, f)          /* vres = v0 + f*v1 */
98 < register FVECT  vres, v0, v1;
99 < register double  f;
97 > fvsum(                          /* vres = v0 + f*v1 */
98 > FVECT vres,
99 > FVECT v0,
100 > FVECT v1,
101 > double f
102 > )
103   {
104          vres[0] = v0[0] + f*v1[0];
105          vres[1] = v0[1] + f*v1[1];
# Line 94 | Line 108 | register double  f;
108  
109  
110   double
111 < normalize(v)                    /* normalize a vector, return old magnitude */
112 < register FVECT  v;
111 > normalize(                      /* normalize a vector, return old magnitude */
112 > FVECT  v
113 > )
114   {
115 <        register double  len, d;
115 >        double  len, d;
116          
117          d = DOT(v, v);
118          
119 <        if (d <= 0.0)
119 >        if (d == 0.0)
120                  return(0.0);
121          
122 <        if (d <= 1.0+FTINY && d >= 1.0-FTINY)
122 >        if (d <= 1.0+FTINY && d >= 1.0-FTINY) {
123                  len = 0.5 + 0.5*d;      /* first order approximation */
124 <        else
124 >                d = 2.0 - len;
125 >        } else {
126                  len = sqrt(d);
127 <
128 <        v[0] *= d = 1.0/len;
127 >                d = 1.0/len;
128 >        }
129 >        v[0] *= d;
130          v[1] *= d;
131          v[2] *= d;
132  
# Line 117 | Line 134 | register FVECT  v;
134   }
135  
136  
137 + int
138 + closestapproach(                        /* closest approach of two rays */
139 + RREAL t[2],             /* returned distances along each ray */
140 + FVECT rorg0,            /* first origin */
141 + FVECT rdir0,            /* first direction (normalized) */
142 + FVECT rorg1,            /* second origin */
143 + FVECT rdir1             /* second direction (normalized) */
144 + )
145 + {
146 +        double  dotprod = DOT(rdir0, rdir1);
147 +        double  denom = 1. - dotprod*dotprod;
148 +        double  o1o2_d1;
149 +        FVECT   o0o1;
150 +
151 +        if (denom <= FTINY) {           /* check if lines are parallel */
152 +                t[0] = t[1] = 0.0;
153 +                return(0);
154 +        }
155 +        VSUB(o0o1, rorg0, rorg1);
156 +        o1o2_d1 = DOT(o0o1, rdir1);
157 +        t[0] = (o1o2_d1*dotprod - DOT(o0o1,rdir0)) / denom;
158 +        t[1] = o1o2_d1 + t[0]*dotprod;
159 +        return(1);
160 + }
161 +
162 +
163   void
164 < spinvector(vres, vorig, vnorm, theta)   /* rotate vector around normal */
165 < FVECT  vres, vorig, vnorm;
166 < double  theta;
164 > spinvector(                             /* rotate vector around normal */
165 > FVECT vres,             /* returned vector */
166 > FVECT vorig,            /* original vector */
167 > FVECT vnorm,            /* normalized vector for rotation */
168 > double theta            /* left-hand radians */
169 > )
170   {
171          double  sint, cost, normprod;
172          FVECT  vperp;
173 <        register int  i;
173 >        int  i;
174          
175          if (theta == 0.0) {
176                  if (vres != vorig)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines