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.9 by greg, Tue May 14 17:21:50 2019 UTC

# 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.) {
# 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 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)+.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(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  
# Line 93 | Line 118 | int32  dc1, dc2;
118          return(2. - 2.*DOT(v1,v2));
119   }
120  
96
121   double
122 < fdir2diff(dc1, v2)              /* approx. radians^2 between directions */
99 < int32   dc1;
100 < register FVECT  v2;
122 > fdir2diff(int32 dc1, FVECT v2)  /* approx. radians^2 between directions */
123   {
124          FVECT   v1;
125  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines