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.5 by greg, Fri Jun 20 00:25:49 2003 UTC vs.
Revision 2.7 by greg, Fri Jun 27 06:53:21 2003 UTC

# Line 2 | Line 2
2   static const char RCSid[] = "$Id$";
3   #endif
4   /*
5 < * Compute a 4-byte direction code (int32 type defined in standard.h).
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 33 | Line 33 | FVECT  dv;
33                          dc |= FXNEG<<i;
34                  } else
35                          cd[i] = (int)(dv[i] * DCSCALE);
36 +        if (!(cd[0] | cd[1] | cd[2]))
37 +                return(0);              /* zero normal */
38          if (cd[0] <= cd[1]) {
39                  dc |= F1X | cd[0] << F1SFT;
40                  cm = cd[1];
# Line 44 | Line 46 | FVECT  dv;
46                  dc |= F2Z | cd[2] << F2SFT;
47          else
48                  dc |= cm << F2SFT;
49 <        if (!dc)        /* don't generate 0 code */
49 >        if (!dc)        /* don't generate 0 code normally */
50                  dc = F1X;
51          return(dc);
52   }
# Line 57 | Line 59 | register int32 dc;
59   {
60          double  d1, d2, der;
61  
62 +        if (!dc) {              /* special code for zero normal */
63 +                dv[0] = dv[1] = dv[2] = 0.;
64 +                return;
65 +        }
66          d1 = ((dc>>F1SFT & FMASK)+.5)*(1./DCSCALE);
67          d2 = ((dc>>F2SFT & FMASK)+.5)*(1./DCSCALE);
68          der = sqrt(1. - d1*d1 - d2*d2);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines