203 |
|
} |
204 |
|
|
205 |
|
|
206 |
– |
#define DCSCALE 11585.2 /* (1<<13)*sqrt(2) */ |
207 |
– |
#define FXNEG 01 |
208 |
– |
#define FYNEG 02 |
209 |
– |
#define FZNEG 04 |
210 |
– |
#define F1X 010 |
211 |
– |
#define F2Z 020 |
212 |
– |
#define F1SFT 5 |
213 |
– |
#define F2SFT 18 |
214 |
– |
#define FMASK 0x1fff |
215 |
– |
|
216 |
– |
static int4 |
217 |
– |
encodedir(dv) /* encode a normalized direction vector */ |
218 |
– |
FVECT dv; |
219 |
– |
{ |
220 |
– |
register int4 dc = 0; |
221 |
– |
int cd[3], cm; |
222 |
– |
register int i; |
223 |
– |
|
224 |
– |
for (i = 0; i < 3; i++) |
225 |
– |
if (dv[i] < 0.) { |
226 |
– |
cd[i] = dv[i] * -DCSCALE; |
227 |
– |
dc |= 1<<i; |
228 |
– |
} else |
229 |
– |
cd[i] = dv[i] * DCSCALE; |
230 |
– |
if (cd[0] <= cd[1]) { |
231 |
– |
dc |= F1X | cd[0] << F1SFT; |
232 |
– |
cm = cd[1]; |
233 |
– |
} else { |
234 |
– |
dc |= cd[1] << F1SFT; |
235 |
– |
cm = cd[0]; |
236 |
– |
} |
237 |
– |
if (cd[2] <= cm) |
238 |
– |
dc |= F2Z | cd[2] << F2SFT; |
239 |
– |
else |
240 |
– |
dc |= cm << F2SFT; |
241 |
– |
return(dc); |
242 |
– |
} |
243 |
– |
|
244 |
– |
|
245 |
– |
static |
246 |
– |
decodedir(dv, dc) /* decode a normalized direction vector */ |
247 |
– |
register FVECT dv; /* returned */ |
248 |
– |
register int4 dc; |
249 |
– |
{ |
250 |
– |
double d1, d2, der; |
251 |
– |
|
252 |
– |
d1 = ((dc>>F1SFT & FMASK)+.5)/DCSCALE; |
253 |
– |
d2 = ((dc>>F2SFT & FMASK)+.5)/DCSCALE; |
254 |
– |
der = sqrt(1. - d1*d1 - d2*d2); |
255 |
– |
if (dc & F1X) { |
256 |
– |
dv[0] = d1; |
257 |
– |
if (dc & F2Z) { dv[1] = der; dv[2] = d2; } |
258 |
– |
else { dv[1] = d2; dv[2] = der; } |
259 |
– |
} else { |
260 |
– |
dv[1] = d1; |
261 |
– |
if (dc & F2Z) { dv[0] = der; dv[2] = d2; } |
262 |
– |
else { dv[0] = d2; dv[2] = der; } |
263 |
– |
} |
264 |
– |
if (dc & FXNEG) dv[0] = -dv[0]; |
265 |
– |
if (dc & FYNEG) dv[1] = -dv[1]; |
266 |
– |
if (dc & FZNEG) dv[2] = -dv[2]; |
267 |
– |
} |
268 |
– |
|
269 |
– |
|
270 |
– |
static double |
271 |
– |
dir2diff(dc1, dc2) /* relative radians^2 between directions */ |
272 |
– |
int4 dc1, dc2; |
273 |
– |
{ |
274 |
– |
FVECT v1, v2; |
275 |
– |
|
276 |
– |
decodedir(v1, dc1); |
277 |
– |
decodedir(v2, dc2); |
278 |
– |
|
279 |
– |
return(2. - 2.*DOT(v1,v2)); |
280 |
– |
} |
281 |
– |
|
282 |
– |
|
283 |
– |
static double |
284 |
– |
fdir2diff(dc1, v2) /* relative radians^2 between directions */ |
285 |
– |
int4 dc1; |
286 |
– |
register FVECT v2; |
287 |
– |
{ |
288 |
– |
FVECT v1; |
289 |
– |
|
290 |
– |
decodedir(v1, dc1); |
291 |
– |
|
292 |
– |
return(2. - 2.*DOT(v1,v2)); |
293 |
– |
} |
294 |
– |
|
295 |
– |
|
206 |
|
int |
207 |
|
qtFindLeaf(x, y) /* find closest leaf to (x,y) */ |
208 |
|
int x, y; |