225 |
|
} |
226 |
|
|
227 |
|
/* Compute outgoing vector from grid position */ |
228 |
+ |
#if 1 |
229 |
|
void |
230 |
|
ovec_from_pos(FVECT vec, int xpos, int ypos) |
231 |
< |
{ |
231 |
> |
{ /* precomputed table version */ |
232 |
> |
static int qsiz = 0; |
233 |
> |
static float (*q_uv)[2] = NULL; |
234 |
> |
|
235 |
> |
if (vec == NULL) { /* just free table? */ |
236 |
> |
if (q_uv) free(q_uv); |
237 |
> |
qsiz = 0; |
238 |
> |
return; |
239 |
> |
} |
240 |
> |
if (qsiz != grid_res>>1) { |
241 |
> |
int x, y; /* (re)make positive quadrant table */ |
242 |
> |
RREAL uv[2]; |
243 |
> |
double r; |
244 |
> |
if (q_uv) free(q_uv); |
245 |
> |
qsiz = grid_res>>1; |
246 |
> |
q_uv = (float (*)[2])malloc(sizeof(float)*2*qsiz*qsiz); |
247 |
> |
for (y = qsiz; y--; ) |
248 |
> |
for (x = qsiz; x--; ) { |
249 |
> |
square2disk(uv, 0.5 + (x+.5)/grid_res, |
250 |
> |
0.5 + (y+.5)/grid_res); |
251 |
> |
/* uniform hemispherical projection */ |
252 |
> |
r = sqrt(2. - uv[0]*uv[0] - uv[1]*uv[1]); |
253 |
> |
q_uv[qsiz*y + x][0] = (float)(r*uv[0]); |
254 |
> |
q_uv[qsiz*y + x][1] = (float)(r*uv[1]); |
255 |
> |
} |
256 |
> |
} |
257 |
> |
/* put in positive quadrant */ |
258 |
> |
if (xpos >= qsiz) { xpos -= qsiz; vec[0] = 1.; } |
259 |
> |
else { xpos = qsiz-1 - xpos; vec[0] = -1.; } |
260 |
> |
if (ypos >= qsiz) { ypos -= qsiz; vec[1] = 1.; } |
261 |
> |
else { ypos = qsiz-1 - ypos; vec[1] = -1.; } |
262 |
> |
|
263 |
> |
vec[0] *= (RREAL)q_uv[qsiz*ypos + xpos][0]; |
264 |
> |
vec[1] *= (RREAL)q_uv[qsiz*ypos + xpos][1]; |
265 |
> |
vec[2] = output_orient*sqrt(1. - vec[0]*vec[0] - vec[1]*vec[1]); |
266 |
> |
} |
267 |
> |
#else |
268 |
> |
void |
269 |
> |
ovec_from_pos(FVECT vec, int xpos, int ypos) |
270 |
> |
{ /* table-free version */ |
271 |
|
RREAL uv[2]; |
272 |
|
double r2; |
273 |
< |
|
273 |
> |
|
274 |
> |
if (vec == NULL) |
275 |
> |
return; |
276 |
> |
|
277 |
|
square2disk(uv, (xpos+.5)/grid_res, (ypos+.5)/grid_res); |
278 |
|
/* uniform hemispherical projection */ |
279 |
|
r2 = uv[0]*uv[0] + uv[1]*uv[1]; |
282 |
|
vec[1] *= uv[1]; |
283 |
|
vec[2] = output_orient*(1. - r2); |
284 |
|
} |
285 |
+ |
#endif |
286 |
|
|
287 |
|
/* Compute grid position from normalized input/output vector */ |
288 |
|
void |