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.1 by greg, Tue Mar 4 05:49:21 2003 UTC vs.
Revision 2.8 by greg, Fri Nov 9 01:35:00 2012 UTC

# Line 1 | Line 1
1   #ifndef lint
2 < static const char       RCSid[] = "$Id$";
2 > static const char RCSid[] = "$Id$";
3   #endif
4   /*
5 < * Compute 4-byte direction code (assume this fits into int)
5 > * Compute a 4-byte direction code (externals defined in rtmath.h).
6 > *
7 > * Mean accuracy is 0.0022 degrees, with a maximum error of 0.0058 degrees.
8   */
9  
10 < #include "standard.h"
10 > #include "rtmath.h"
11  
12   #define DCSCALE         11585.2         /* (1<<13)*sqrt(2) */
13   #define FXNEG           01
# Line 17 | Line 19 | static const char      RCSid[] = "$Id$";
19   #define F2SFT           18
20   #define FMASK           0x1fff
21  
22 < int4
23 < encodedir(dv)           /* encode a normalized direction vector */
22 < FVECT   dv;
22 > int32
23 > encodedir(FVECT dv)             /* encode a normalized direction vector */
24   {
25 <        register int4   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] = dv[i] * -DCSCALE;
31 >                        cd[i] = (int)(dv[i] * -DCSCALE);
32                          dc |= FXNEG<<i;
33                  } else
34 <                        cd[i] = dv[i] * DCSCALE;
34 >                        cd[i] = (int)(dv[i] * DCSCALE);
35 >        if (!(cd[0] | cd[1] | cd[2]))
36 >                return(0);              /* zero normal */
37          if (cd[0] <= cd[1]) {
38                  dc |= F1X | cd[0] << F1SFT;
39                  cm = cd[1];
# Line 42 | Line 45 | FVECT  dv;
45                  dc |= F2Z | cd[2] << F2SFT;
46          else
47                  dc |= cm << F2SFT;
48 +        if (!dc)        /* don't generate 0 code normally */
49 +                dc = F1X;
50          return(dc);
51   }
52  
53  
54   void
55 < decodedir(dv, dc)       /* decode a normalized direction vector */
51 < register FVECT  dv;     /* returned */
52 < register int4   dc;
55 > decodedir(FVECT dv, int32 dc)   /* decode a normalized direction vector */
56   {
57          double  d1, d2, der;
58  
59 +        if (!dc) {              /* special code for zero normal */
60 +                dv[0] = dv[1] = dv[2] = 0.;
61 +                return;
62 +        }
63          d1 = ((dc>>F1SFT & FMASK)+.5)*(1./DCSCALE);
64          d2 = ((dc>>F2SFT & FMASK)+.5)*(1./DCSCALE);
65          der = sqrt(1. - d1*d1 - d2*d2);
# Line 72 | Line 79 | register int4  dc;
79  
80  
81   double
82 < dir2diff(dc1, dc2)              /* approx. radians^2 between directions */
76 < int4    dc1, dc2;
82 > dir2diff(int32 dc1, int32 dc2)  /* approx. radians^2 between directions */
83   {
84          FVECT   v1, v2;
85  
# Line 85 | Line 91 | int4   dc1, dc2;
91  
92  
93   double
94 < fdir2diff(dc1, v2)              /* approx. radians^2 between directions */
89 < int4    dc1;
90 < register FVECT  v2;
94 > fdir2diff(int32 dc1, FVECT v2)  /* approx. radians^2 between directions */
95   {
96          FVECT   v1;
97  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines