| 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 (int32 type defined in standard.h). |
| 6 |
> |
* |
| 7 |
> |
* Mean accuracy is 0.0022 degrees, with a maximum error of 0.0058 degrees. |
| 8 |
|
*/ |
| 9 |
|
|
| 10 |
|
#include "standard.h" |
| 19 |
|
#define F2SFT 18 |
| 20 |
|
#define FMASK 0x1fff |
| 21 |
|
|
| 22 |
< |
int4 |
| 22 |
> |
int32 |
| 23 |
|
encodedir(dv) /* encode a normalized direction vector */ |
| 24 |
|
FVECT dv; |
| 25 |
|
{ |
| 26 |
< |
register int4 dc = 0; |
| 26 |
> |
register int32 dc = 0; |
| 27 |
|
int cd[3], cm; |
| 28 |
|
register int i; |
| 29 |
|
|
| 30 |
|
for (i = 0; i < 3; i++) |
| 31 |
|
if (dv[i] < 0.) { |
| 32 |
< |
cd[i] = dv[i] * -DCSCALE; |
| 32 |
> |
cd[i] = (int)(dv[i] * -DCSCALE); |
| 33 |
|
dc |= FXNEG<<i; |
| 34 |
|
} else |
| 35 |
< |
cd[i] = dv[i] * DCSCALE; |
| 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]; |
| 46 |
|
dc |= F2Z | cd[2] << F2SFT; |
| 47 |
|
else |
| 48 |
|
dc |= cm << F2SFT; |
| 49 |
+ |
if (!dc) /* don't generate 0 code normally */ |
| 50 |
+ |
dc = F1X; |
| 51 |
|
return(dc); |
| 52 |
|
} |
| 53 |
|
|
| 55 |
|
void |
| 56 |
|
decodedir(dv, dc) /* decode a normalized direction vector */ |
| 57 |
|
register FVECT dv; /* returned */ |
| 58 |
< |
register int4 dc; |
| 58 |
> |
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); |
| 83 |
|
|
| 84 |
|
double |
| 85 |
|
dir2diff(dc1, dc2) /* approx. radians^2 between directions */ |
| 86 |
< |
int4 dc1, dc2; |
| 86 |
> |
int32 dc1, dc2; |
| 87 |
|
{ |
| 88 |
|
FVECT v1, v2; |
| 89 |
|
|
| 96 |
|
|
| 97 |
|
double |
| 98 |
|
fdir2diff(dc1, v2) /* approx. radians^2 between directions */ |
| 99 |
< |
int4 dc1; |
| 99 |
> |
int32 dc1; |
| 100 |
|
register FVECT v2; |
| 101 |
|
{ |
| 102 |
|
FVECT v1; |