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.8 by greg, Fri Nov 9 01:35:00 2012 UTC vs.
Revision 2.9 by greg, Tue May 14 17:21:50 2019 UTC

# Line 50 | Line 50 | encodedir(FVECT dv)            /* encode a normalized direction
50          return(dc);
51   }
52  
53 + #if 0           /* original version for reference */
54  
55   void
56   decodedir(FVECT dv, int32 dc)   /* decode a normalized direction vector */
# Line 77 | Line 78 | decodedir(FVECT dv, int32 dc)  /* decode a normalized d
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)+.5)*(1./DCSCALE);
98 +        d2 = ((dc>>F2SFT & FMASK)+.5)*(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(int32 dc1, int32 dc2)  /* approx. radians^2 between directions */
112   {
# Line 88 | Line 117 | dir2diff(int32 dc1, int32 dc2) /* approx. radians^2 be
117  
118          return(2. - 2.*DOT(v1,v2));
119   }
91
120  
121   double
122   fdir2diff(int32 dc1, FVECT v2)  /* approx. radians^2 between directions */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines