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

Comparing ray/src/common/dircode.c (file contents):
Revision 2.7 by greg, Fri Jun 27 06:53:21 2003 UTC vs.
Revision 2.13 by greg, Tue Apr 7 18:20:52 2020 UTC

# Line 9 | Line 9 | static const char RCSid[] = "$Id$";
9  
10   #include "rtmath.h"
11  
12 < #define DCSCALE         11585.2         /* (1<<13)*sqrt(2) */
12 > #define DCSCALE         11584.5         /* ((1<<13)-.5)*sqrt(2) */
13   #define FXNEG           01
14   #define FYNEG           02
15   #define FZNEG           04
# Line 20 | Line 20 | static const char RCSid[] = "$Id$";
20   #define FMASK           0x1fff
21  
22   int32
23 < encodedir(dv)           /* encode a normalized direction vector */
24 < FVECT   dv;
23 > encodedir(FVECT dv)             /* encode a normalized direction vector */
24   {
25 <        register int32  dc = 0;
25 >        int32   dc = 0;
26          int     cd[3], cm;
27 <        register int    i;
27 >        int     i;
28  
29          for (i = 0; i < 3; i++)
30                  if (dv[i] < 0.) {
31 <                        cd[i] = (int)(dv[i] * -DCSCALE);
31 >                        cd[i] = (int)(dv[i] * -DCSCALE + .5);
32                          dc |= FXNEG<<i;
33                  } else
34 <                        cd[i] = (int)(dv[i] * DCSCALE);
34 >                        cd[i] = (int)(dv[i] * DCSCALE + .5);
35          if (!(cd[0] | cd[1] | cd[2]))
36                  return(0);              /* zero normal */
37          if (cd[0] <= cd[1]) {
# Line 51 | Line 50 | FVECT  dv;
50          return(dc);
51   }
52  
53 + #if 0           /* original version for reference */
54  
55   void
56 < decodedir(dv, dc)       /* decode a normalized direction vector */
57 < register FVECT  dv;     /* returned */
58 < register int32  dc;
56 > decodedir(FVECT dv, int32 dc)   /* decode a normalized direction vector */
57   {
58          double  d1, d2, der;
59  
# Line 63 | Line 61 | register int32 dc;
61                  dv[0] = dv[1] = dv[2] = 0.;
62                  return;
63          }
64 <        d1 = ((dc>>F1SFT & FMASK)+.5)*(1./DCSCALE);
65 <        d2 = ((dc>>F2SFT & FMASK)+.5)*(1./DCSCALE);
64 >        d1 = (dc>>F1SFT & FMASK)*(1./DCSCALE);
65 >        d2 = (dc>>F2SFT & FMASK)*(1./DCSCALE);
66          der = sqrt(1. - d1*d1 - d2*d2);
67          if (dc & F1X) {
68                  dv[0] = d1;
# Line 80 | Line 78 | register int32 dc;
78          if (dc & FZNEG) dv[2] = -dv[2];
79   }
80  
81 + #else  
82  
83 + void
84 + decodedir(FVECT dv, int32 dc)   /* decode a normalized direction vector */
85 + {
86 +        static const short      itab[4][3] = {
87 +                                        {1,0,2},{0,1,2},{1,2,0},{0,2,1}
88 +                                };
89 +        static const RREAL      neg[2] = {1., -1.};
90 +        const int               ndx = ((dc & F2Z) != 0)<<1 | ((dc & F1X) != 0);
91 +        double                  d1, d2, der;
92 +
93 +        if (!dc) {              /* special code for zero normal */
94 +                dv[0] = dv[1] = dv[2] = 0.;
95 +                return;
96 +        }
97 +        d1 = (dc>>F1SFT & FMASK)*(1./DCSCALE);
98 +        d2 = (dc>>F2SFT & FMASK)*(1./DCSCALE);
99 +        der = sqrt(1. - d1*d1 - d2*d2);
100 +        dv[itab[ndx][0]] = d1;
101 +        dv[itab[ndx][1]] = d2;
102 +        dv[itab[ndx][2]] = der;
103 +        dv[0] *= neg[(dc&FXNEG)!=0];
104 +        dv[1] *= neg[(dc&FYNEG)!=0];
105 +        dv[2] *= neg[(dc&FZNEG)!=0];
106 + }
107 +
108 + #endif
109 +
110   double
111 < dir2diff(dc1, dc2)              /* approx. radians^2 between directions */
86 < int32   dc1, dc2;
111 > dir2diff(int32 dc1, int32 dc2)  /* approx. radians^2 between directions */
112   {
113          FVECT   v1, v2;
114  
115 +        if (dc1 == dc2)
116 +                return 0.;
117 +
118          decodedir(v1, dc1);
119          decodedir(v2, dc2);
120  
121          return(2. - 2.*DOT(v1,v2));
122   }
123  
96
124   double
125 < fdir2diff(dc1, v2)              /* approx. radians^2 between directions */
99 < int32   dc1;
100 < register FVECT  v2;
125 > fdir2diff(int32 dc1, FVECT v2)  /* approx. radians^2 between directions */
126   {
127          FVECT   v1;
128  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines