5 |
|
* Routines to do the actual calculation for mkillum |
6 |
|
*/ |
7 |
|
|
8 |
+ |
#include <string.h> |
9 |
+ |
|
10 |
|
#include "mkillum.h" |
11 |
|
#include "face.h" |
12 |
|
#include "cone.h" |
13 |
|
#include "random.h" |
14 |
|
|
15 |
|
|
16 |
< |
o_default(ob, il, rt, nm) /* default illum action */ |
17 |
< |
OBJREC *ob; |
18 |
< |
struct illum_args *il; |
19 |
< |
struct rtproc *rt; |
20 |
< |
char *nm; |
16 |
> |
COLORV * distarr = NULL; /* distribution array */ |
17 |
> |
int distsiz = 0; |
18 |
> |
|
19 |
> |
|
20 |
> |
void |
21 |
> |
newdist( /* allocate & clear distribution array */ |
22 |
> |
int siz |
23 |
> |
) |
24 |
|
{ |
25 |
+ |
if (siz == 0) { |
26 |
+ |
if (distsiz > 0) |
27 |
+ |
free((void *)distarr); |
28 |
+ |
distarr = NULL; |
29 |
+ |
distsiz = 0; |
30 |
+ |
return; |
31 |
+ |
} |
32 |
+ |
if (distsiz < siz) { |
33 |
+ |
if (distsiz > 0) |
34 |
+ |
free((void *)distarr); |
35 |
+ |
distarr = (COLORV *)malloc(sizeof(COLOR)*siz); |
36 |
+ |
if (distarr == NULL) |
37 |
+ |
error(SYSTEM, "out of memory in newdist"); |
38 |
+ |
distsiz = siz; |
39 |
+ |
} |
40 |
+ |
memset(distarr, '\0', sizeof(COLOR)*siz); |
41 |
+ |
} |
42 |
+ |
|
43 |
+ |
|
44 |
+ |
int |
45 |
+ |
process_ray(RAY *r, int rv) |
46 |
+ |
{ |
47 |
+ |
COLORV *colp; |
48 |
+ |
|
49 |
+ |
if (rv == 0) |
50 |
+ |
return(0); |
51 |
+ |
if (rv < 0) |
52 |
+ |
error(USER, "ray tracing process died"); |
53 |
+ |
if (r->rno >= distsiz) |
54 |
+ |
error(INTERNAL, "bad returned index in process_ray"); |
55 |
+ |
colp = &distarr[r->rno * 3]; |
56 |
+ |
addcolor(colp, r->rcol); |
57 |
+ |
return(1); |
58 |
+ |
} |
59 |
+ |
|
60 |
+ |
|
61 |
+ |
void |
62 |
+ |
raysamp( /* queue a ray sample */ |
63 |
+ |
int ndx, |
64 |
+ |
FVECT org, |
65 |
+ |
FVECT dir |
66 |
+ |
) |
67 |
+ |
{ |
68 |
+ |
RAY myRay; |
69 |
+ |
int rv; |
70 |
+ |
|
71 |
+ |
if ((ndx < 0) | (ndx >= distsiz)) |
72 |
+ |
error(INTERNAL, "bad index in raysamp"); |
73 |
+ |
VCOPY(myRay.rorg, org); |
74 |
+ |
VCOPY(myRay.rdir, dir); |
75 |
+ |
myRay.rmax = .0; |
76 |
+ |
rayorigin(&myRay, PRIMARY, NULL, NULL); |
77 |
+ |
myRay.rno = ndx; |
78 |
+ |
/* queue ray, check result */ |
79 |
+ |
process_ray(&myRay, ray_pqueue(&myRay)); |
80 |
+ |
} |
81 |
+ |
|
82 |
+ |
|
83 |
+ |
void |
84 |
+ |
rayclean() /* finish all pending rays */ |
85 |
+ |
{ |
86 |
+ |
RAY myRay; |
87 |
+ |
|
88 |
+ |
while (process_ray(&myRay, ray_presult(&myRay, 0))) |
89 |
+ |
; |
90 |
+ |
} |
91 |
+ |
|
92 |
+ |
|
93 |
+ |
static void |
94 |
+ |
mkaxes( /* compute u and v to go with n */ |
95 |
+ |
FVECT u, |
96 |
+ |
FVECT v, |
97 |
+ |
FVECT n |
98 |
+ |
) |
99 |
+ |
{ |
100 |
+ |
register int i; |
101 |
+ |
|
102 |
+ |
v[0] = v[1] = v[2] = 0.0; |
103 |
+ |
for (i = 0; i < 3; i++) |
104 |
+ |
if (n[i] < 0.6 && n[i] > -0.6) |
105 |
+ |
break; |
106 |
+ |
v[i] = 1.0; |
107 |
+ |
fcross(u, v, n); |
108 |
+ |
normalize(u); |
109 |
+ |
fcross(v, n, u); |
110 |
+ |
} |
111 |
+ |
|
112 |
+ |
|
113 |
+ |
static void |
114 |
+ |
rounddir( /* compute uniform spherical direction */ |
115 |
+ |
register FVECT dv, |
116 |
+ |
double alt, |
117 |
+ |
double azi |
118 |
+ |
) |
119 |
+ |
{ |
120 |
+ |
double d1, d2; |
121 |
+ |
|
122 |
+ |
dv[2] = 1. - 2.*alt; |
123 |
+ |
d1 = sqrt(1. - dv[2]*dv[2]); |
124 |
+ |
d2 = 2.*PI * azi; |
125 |
+ |
dv[0] = d1*cos(d2); |
126 |
+ |
dv[1] = d1*sin(d2); |
127 |
+ |
} |
128 |
+ |
|
129 |
+ |
|
130 |
+ |
static void |
131 |
+ |
flatdir( /* compute uniform hemispherical direction */ |
132 |
+ |
register FVECT dv, |
133 |
+ |
double alt, |
134 |
+ |
double azi |
135 |
+ |
) |
136 |
+ |
{ |
137 |
+ |
double d1, d2; |
138 |
+ |
|
139 |
+ |
d1 = sqrt(alt); |
140 |
+ |
d2 = 2.*PI * azi; |
141 |
+ |
dv[0] = d1*cos(d2); |
142 |
+ |
dv[1] = d1*sin(d2); |
143 |
+ |
dv[2] = sqrt(1. - alt); |
144 |
+ |
} |
145 |
+ |
|
146 |
+ |
|
147 |
+ |
int |
148 |
+ |
my_default( /* default illum action */ |
149 |
+ |
OBJREC *ob, |
150 |
+ |
struct illum_args *il, |
151 |
+ |
char *nm |
152 |
+ |
) |
153 |
+ |
{ |
154 |
|
sprintf(errmsg, "(%s): cannot make illum for %s \"%s\"", |
155 |
|
nm, ofun[ob->otype].funame, ob->oname); |
156 |
|
error(WARNING, errmsg); |
157 |
|
printobj(il->altmat, ob); |
158 |
+ |
return(1); |
159 |
|
} |
160 |
|
|
161 |
|
|
162 |
< |
o_face(ob, il, rt, nm) /* make an illum face */ |
163 |
< |
OBJREC *ob; |
164 |
< |
struct illum_args *il; |
165 |
< |
struct rtproc *rt; |
166 |
< |
char *nm; |
162 |
> |
int |
163 |
> |
my_face( /* make an illum face */ |
164 |
> |
OBJREC *ob, |
165 |
> |
struct illum_args *il, |
166 |
> |
char *nm |
167 |
> |
) |
168 |
|
{ |
169 |
|
#define MAXMISS (5*n*il->nsamps) |
170 |
< |
int dim[3]; |
171 |
< |
int n, nalt, nazi, h; |
36 |
< |
float *distarr; |
170 |
> |
int dim[2]; |
171 |
> |
int n, nalt, nazi, h, alti; |
172 |
|
double sp[2], r1, r2; |
173 |
|
FVECT dn, org, dir; |
174 |
|
FVECT u, v; |
175 |
|
double ur[2], vr[2]; |
176 |
+ |
MAT4 xfm; |
177 |
|
int nmisses; |
178 |
< |
register FACE *fa; |
178 |
> |
FACE *fa; |
179 |
|
register int i, j; |
180 |
|
/* get/check arguments */ |
181 |
|
fa = getface(ob); |
182 |
|
if (fa->area == 0.0) { |
183 |
|
freeface(ob); |
184 |
< |
o_default(ob, il, rt, nm); |
49 |
< |
return; |
184 |
> |
return(my_default(ob, il, nm)); |
185 |
|
} |
186 |
|
/* set up sampling */ |
187 |
< |
if (il->sampdens <= 0) |
188 |
< |
nalt = nazi = 1; |
189 |
< |
else { |
187 |
> |
if (il->sampdens <= 0) { |
188 |
> |
nalt = nazi = 1; /* diffuse assumption */ |
189 |
> |
} else { |
190 |
|
n = PI * il->sampdens; |
191 |
|
nalt = sqrt(n/PI) + .5; |
192 |
|
nazi = PI*nalt + .5; |
193 |
|
} |
194 |
< |
n = nalt*nazi; |
195 |
< |
distarr = (float *)calloc(n, 3*sizeof(float)); |
196 |
< |
if (distarr == NULL) |
197 |
< |
error(SYSTEM, "out of memory in o_face"); |
198 |
< |
/* take first edge longer than sqrt(area) */ |
194 |
> |
if (il->sd != NULL) { |
195 |
> |
if (!getBSDF_xfm(xfm, fa->norm, il->udir)) { |
196 |
> |
objerror(ob, WARNING, "illegal up direction"); |
197 |
> |
freeface(ob); |
198 |
> |
return(my_default(ob, il, nm)); |
199 |
> |
} |
200 |
> |
n = il->sd->ninc; |
201 |
> |
} else |
202 |
> |
n = nazi*nalt; |
203 |
> |
newdist(n); |
204 |
> |
/* take first edge >= sqrt(area) */ |
205 |
|
for (j = fa->nv-1, i = 0; i < fa->nv; j = i++) { |
206 |
|
u[0] = VERTEX(fa,i)[0] - VERTEX(fa,j)[0]; |
207 |
|
u[1] = VERTEX(fa,i)[1] - VERTEX(fa,j)[1]; |
229 |
|
dim[0] = random(); |
230 |
|
/* sample polygon */ |
231 |
|
nmisses = 0; |
232 |
< |
for (dim[1] = 0; dim[1] < nalt; dim[1]++) |
92 |
< |
for (dim[2] = 0; dim[2] < nazi; dim[2]++) |
232 |
> |
for (dim[1] = 0; dim[1] < n; dim[1]++) |
233 |
|
for (i = 0; i < il->nsamps; i++) { |
234 |
|
/* random direction */ |
235 |
< |
h = ilhash(dim, 3) + i; |
236 |
< |
multisamp(sp, 2, urand(h)); |
237 |
< |
r1 = (dim[1] + sp[0])/nalt; |
238 |
< |
r2 = (dim[2] + sp[1] - .5)/nazi; |
239 |
< |
flatdir(dn, r1, r2); |
240 |
< |
for (j = 0; j < 3; j++) |
241 |
< |
dir[j] = -dn[0]*u[j] - dn[1]*v[j] - dn[2]*fa->norm[j]; |
235 |
> |
h = ilhash(dim, 2) + i; |
236 |
> |
if (il->sd != NULL) { |
237 |
> |
r_BSDF_incvec(dir, il->sd, dim[1], urand(h), xfm); |
238 |
> |
} else { |
239 |
> |
multisamp(sp, 2, urand(h)); |
240 |
> |
alti = dim[1]/nazi; |
241 |
> |
r1 = (alti + sp[0])/nalt; |
242 |
> |
r2 = (dim[1] - alti*nazi + sp[1] - .5)/nazi; |
243 |
> |
flatdir(dn, r1, r2); |
244 |
> |
for (j = 0; j < 3; j++) |
245 |
> |
dir[j] = -dn[0]*u[j] - dn[1]*v[j] - |
246 |
> |
dn[2]*fa->norm[j]; |
247 |
> |
} |
248 |
|
/* random location */ |
249 |
|
do { |
250 |
|
multisamp(sp, 2, urand(h+4862+nmisses)); |
256 |
|
} while (!inface(org, fa) && nmisses++ < MAXMISS); |
257 |
|
if (nmisses > MAXMISS) { |
258 |
|
objerror(ob, WARNING, "bad aspect"); |
259 |
< |
rt->nrays = 0; |
259 |
> |
rayclean(); |
260 |
|
freeface(ob); |
261 |
< |
free((void *)distarr); |
116 |
< |
o_default(ob, il, rt, nm); |
117 |
< |
return; |
261 |
> |
return(my_default(ob, il, nm)); |
262 |
|
} |
263 |
+ |
if (il->sd != NULL && DOT(dir, fa->norm) < -FTINY) |
264 |
+ |
r1 = -1.0001*il->thick - .0001; |
265 |
+ |
else |
266 |
+ |
r1 = .0001; |
267 |
|
for (j = 0; j < 3; j++) |
268 |
< |
org[j] += .001*fa->norm[j]; |
268 |
> |
org[j] += r1*fa->norm[j]; |
269 |
|
/* send sample */ |
270 |
< |
raysamp(distarr+3*(dim[1]*nazi+dim[2]), org, dir, rt); |
270 |
> |
raysamp(dim[1], org, dir); |
271 |
|
} |
272 |
< |
rayflush(rt); |
272 |
> |
rayclean(); |
273 |
> |
if (il->sd != NULL) /* run distribution through BSDF */ |
274 |
> |
redistribute(il->sd, nalt, nazi, u, v, fa->norm, xfm); |
275 |
|
/* write out the face and its distribution */ |
276 |
< |
if (average(il, distarr, nalt*nazi)) { |
276 |
> |
if (average(il, distarr, n)) { |
277 |
|
if (il->sampdens > 0) |
278 |
|
flatout(il, distarr, nalt, nazi, u, v, fa->norm); |
279 |
|
illumout(il, ob); |
281 |
|
printobj(il->altmat, ob); |
282 |
|
/* clean up */ |
283 |
|
freeface(ob); |
284 |
< |
free((void *)distarr); |
284 |
> |
return(0); |
285 |
|
#undef MAXMISS |
286 |
|
} |
287 |
|
|
288 |
|
|
289 |
< |
o_sphere(ob, il, rt, nm) /* make an illum sphere */ |
290 |
< |
register OBJREC *ob; |
291 |
< |
struct illum_args *il; |
292 |
< |
struct rtproc *rt; |
293 |
< |
char *nm; |
289 |
> |
int |
290 |
> |
my_sphere( /* make an illum sphere */ |
291 |
> |
register OBJREC *ob, |
292 |
> |
struct illum_args *il, |
293 |
> |
char *nm |
294 |
> |
) |
295 |
|
{ |
296 |
|
int dim[3]; |
297 |
|
int n, nalt, nazi; |
147 |
– |
float *distarr; |
298 |
|
double sp[4], r1, r2, r3; |
299 |
|
FVECT org, dir; |
300 |
|
FVECT u, v; |
310 |
|
nalt = sqrt(2./PI*n) + .5; |
311 |
|
nazi = PI/2.*nalt + .5; |
312 |
|
} |
313 |
+ |
if (il->sd != NULL) |
314 |
+ |
objerror(ob, WARNING, "BSDF ignored"); |
315 |
|
n = nalt*nazi; |
316 |
< |
distarr = (float *)calloc(n, 3*sizeof(float)); |
165 |
< |
if (distarr == NULL) |
166 |
< |
error(SYSTEM, "out of memory in o_sphere"); |
316 |
> |
newdist(n); |
317 |
|
dim[0] = random(); |
318 |
|
/* sample sphere */ |
319 |
|
for (dim[1] = 0; dim[1] < nalt; dim[1]++) |
338 |
|
dir[j] = -dir[j]; |
339 |
|
} |
340 |
|
/* send sample */ |
341 |
< |
raysamp(distarr+3*(dim[1]*nazi+dim[2]), org, dir, rt); |
341 |
> |
raysamp(dim[1]*nazi+dim[2], org, dir); |
342 |
|
} |
343 |
< |
rayflush(rt); |
343 |
> |
rayclean(); |
344 |
|
/* write out the sphere and its distribution */ |
345 |
< |
if (average(il, distarr, nalt*nazi)) { |
345 |
> |
if (average(il, distarr, n)) { |
346 |
|
if (il->sampdens > 0) |
347 |
|
roundout(il, distarr, nalt, nazi); |
348 |
|
else |
351 |
|
} else |
352 |
|
printobj(il->altmat, ob); |
353 |
|
/* clean up */ |
354 |
< |
free((void *)distarr); |
354 |
> |
return(1); |
355 |
|
} |
356 |
|
|
357 |
|
|
358 |
< |
o_ring(ob, il, rt, nm) /* make an illum ring */ |
359 |
< |
OBJREC *ob; |
360 |
< |
struct illum_args *il; |
361 |
< |
struct rtproc *rt; |
362 |
< |
char *nm; |
358 |
> |
int |
359 |
> |
my_ring( /* make an illum ring */ |
360 |
> |
OBJREC *ob, |
361 |
> |
struct illum_args *il, |
362 |
> |
char *nm |
363 |
> |
) |
364 |
|
{ |
365 |
< |
int dim[3]; |
366 |
< |
int n, nalt, nazi; |
367 |
< |
float *distarr; |
368 |
< |
double sp[4], r1, r2, r3; |
365 |
> |
int dim[2]; |
366 |
> |
int n, nalt, nazi, alti; |
367 |
> |
double sp[2], r1, r2, r3; |
368 |
> |
int h; |
369 |
|
FVECT dn, org, dir; |
370 |
|
FVECT u, v; |
371 |
< |
register CONE *co; |
371 |
> |
MAT4 xfm; |
372 |
> |
CONE *co; |
373 |
|
register int i, j; |
374 |
|
/* get/check arguments */ |
375 |
|
co = getcone(ob, 0); |
381 |
|
nalt = sqrt(n/PI) + .5; |
382 |
|
nazi = PI*nalt + .5; |
383 |
|
} |
384 |
< |
n = nalt*nazi; |
385 |
< |
distarr = (float *)calloc(n, 3*sizeof(float)); |
386 |
< |
if (distarr == NULL) |
387 |
< |
error(SYSTEM, "out of memory in o_ring"); |
384 |
> |
if (il->sd != NULL) { |
385 |
> |
if (!getBSDF_xfm(xfm, co->ad, il->udir)) { |
386 |
> |
objerror(ob, WARNING, "illegal up direction"); |
387 |
> |
freecone(ob); |
388 |
> |
return(my_default(ob, il, nm)); |
389 |
> |
} |
390 |
> |
n = il->sd->ninc; |
391 |
> |
} else |
392 |
> |
n = nazi*nalt; |
393 |
> |
newdist(n); |
394 |
|
mkaxes(u, v, co->ad); |
395 |
|
dim[0] = random(); |
396 |
|
/* sample disk */ |
397 |
< |
for (dim[1] = 0; dim[1] < nalt; dim[1]++) |
240 |
< |
for (dim[2] = 0; dim[2] < nazi; dim[2]++) |
397 |
> |
for (dim[1] = 0; dim[1] < n; dim[1]++) |
398 |
|
for (i = 0; i < il->nsamps; i++) { |
399 |
|
/* next sample point */ |
400 |
< |
multisamp(sp, 4, urand(ilhash(dim,3)+i)); |
400 |
> |
h = ilhash(dim,2) + i; |
401 |
|
/* random direction */ |
402 |
< |
r1 = (dim[1] + sp[0])/nalt; |
403 |
< |
r2 = (dim[2] + sp[1] - .5)/nazi; |
404 |
< |
flatdir(dn, r1, r2); |
405 |
< |
for (j = 0; j < 3; j++) |
402 |
> |
if (il->sd != NULL) { |
403 |
> |
r_BSDF_incvec(dir, il->sd, dim[1], urand(h), xfm); |
404 |
> |
} else { |
405 |
> |
multisamp(sp, 2, urand(h)); |
406 |
> |
alti = dim[1]/nazi; |
407 |
> |
r1 = (alti + sp[0])/nalt; |
408 |
> |
r2 = (dim[1] - alti*nazi + sp[1] - .5)/nazi; |
409 |
> |
flatdir(dn, r1, r2); |
410 |
> |
for (j = 0; j < 3; j++) |
411 |
|
dir[j] = -dn[0]*u[j] - dn[1]*v[j] - dn[2]*co->ad[j]; |
412 |
+ |
} |
413 |
|
/* random location */ |
414 |
+ |
multisamp(sp, 2, urand(h+8371)); |
415 |
|
r3 = sqrt(CO_R0(co)*CO_R0(co) + |
416 |
< |
sp[2]*(CO_R1(co)*CO_R1(co) - CO_R0(co)*CO_R0(co))); |
417 |
< |
r2 = 2.*PI*sp[3]; |
416 |
> |
sp[0]*(CO_R1(co)*CO_R1(co) - CO_R0(co)*CO_R0(co))); |
417 |
> |
r2 = 2.*PI*sp[1]; |
418 |
|
r1 = r3*cos(r2); |
419 |
|
r2 = r3*sin(r2); |
420 |
+ |
if (il->sd != NULL && DOT(dir, co->ad) < -FTINY) |
421 |
+ |
r3 = -1.0001*il->thick - .0001; |
422 |
+ |
else |
423 |
+ |
r3 = .0001; |
424 |
|
for (j = 0; j < 3; j++) |
425 |
|
org[j] = CO_P0(co)[j] + r1*u[j] + r2*v[j] + |
426 |
< |
.001*co->ad[j]; |
259 |
< |
|
426 |
> |
r3*co->ad[j]; |
427 |
|
/* send sample */ |
428 |
< |
raysamp(distarr+3*(dim[1]*nazi+dim[2]), org, dir, rt); |
428 |
> |
raysamp(dim[1], org, dir); |
429 |
|
} |
430 |
< |
rayflush(rt); |
430 |
> |
rayclean(); |
431 |
> |
if (il->sd != NULL) /* run distribution through BSDF */ |
432 |
> |
redistribute(il->sd, nalt, nazi, u, v, co->ad, xfm); |
433 |
|
/* write out the ring and its distribution */ |
434 |
< |
if (average(il, distarr, nalt*nazi)) { |
434 |
> |
if (average(il, distarr, n)) { |
435 |
|
if (il->sampdens > 0) |
436 |
|
flatout(il, distarr, nalt, nazi, u, v, co->ad); |
437 |
|
illumout(il, ob); |
439 |
|
printobj(il->altmat, ob); |
440 |
|
/* clean up */ |
441 |
|
freecone(ob); |
442 |
< |
free((void *)distarr); |
274 |
< |
} |
275 |
< |
|
276 |
< |
|
277 |
< |
raysamp(res, org, dir, rt) /* compute a ray sample */ |
278 |
< |
float res[3]; |
279 |
< |
FVECT org, dir; |
280 |
< |
register struct rtproc *rt; |
281 |
< |
{ |
282 |
< |
register float *fp; |
283 |
< |
|
284 |
< |
if (rt->nrays == rt->bsiz) |
285 |
< |
rayflush(rt); |
286 |
< |
rt->dest[rt->nrays] = res; |
287 |
< |
fp = rt->buf + 6*rt->nrays++; |
288 |
< |
*fp++ = org[0]; *fp++ = org[1]; *fp++ = org[2]; |
289 |
< |
*fp++ = dir[0]; *fp++ = dir[1]; *fp = dir[2]; |
290 |
< |
} |
291 |
< |
|
292 |
< |
|
293 |
< |
rayflush(rt) /* flush buffered rays */ |
294 |
< |
register struct rtproc *rt; |
295 |
< |
{ |
296 |
< |
register int i; |
297 |
< |
|
298 |
< |
if (rt->nrays <= 0) |
299 |
< |
return; |
300 |
< |
bzero(rt->buf+6*rt->nrays, 6*sizeof(float)); |
301 |
< |
errno = 0; |
302 |
< |
if ( process(&(rt->pd), (char *)rt->buf, (char *)rt->buf, |
303 |
< |
3*sizeof(float)*(rt->nrays+1), |
304 |
< |
6*sizeof(float)*(rt->nrays+1)) < |
305 |
< |
3*sizeof(float)*(rt->nrays+1) ) |
306 |
< |
error(SYSTEM, "error reading from rtrace process"); |
307 |
< |
i = rt->nrays; |
308 |
< |
while (i--) { |
309 |
< |
rt->dest[i][0] += rt->buf[3*i]; |
310 |
< |
rt->dest[i][1] += rt->buf[3*i+1]; |
311 |
< |
rt->dest[i][2] += rt->buf[3*i+2]; |
312 |
< |
} |
313 |
< |
rt->nrays = 0; |
314 |
< |
} |
315 |
< |
|
316 |
< |
|
317 |
< |
mkaxes(u, v, n) /* compute u and v to go with n */ |
318 |
< |
FVECT u, v, n; |
319 |
< |
{ |
320 |
< |
register int i; |
321 |
< |
|
322 |
< |
v[0] = v[1] = v[2] = 0.0; |
323 |
< |
for (i = 0; i < 3; i++) |
324 |
< |
if (n[i] < 0.6 && n[i] > -0.6) |
325 |
< |
break; |
326 |
< |
v[i] = 1.0; |
327 |
< |
fcross(u, v, n); |
328 |
< |
normalize(u); |
329 |
< |
fcross(v, n, u); |
330 |
< |
} |
331 |
< |
|
332 |
< |
|
333 |
< |
rounddir(dv, alt, azi) /* compute uniform spherical direction */ |
334 |
< |
register FVECT dv; |
335 |
< |
double alt, azi; |
336 |
< |
{ |
337 |
< |
double d1, d2; |
338 |
< |
|
339 |
< |
dv[2] = 1. - 2.*alt; |
340 |
< |
d1 = sqrt(1. - dv[2]*dv[2]); |
341 |
< |
d2 = 2.*PI * azi; |
342 |
< |
dv[0] = d1*cos(d2); |
343 |
< |
dv[1] = d1*sin(d2); |
344 |
< |
} |
345 |
< |
|
346 |
< |
|
347 |
< |
flatdir(dv, alt, azi) /* compute uniform hemispherical direction */ |
348 |
< |
register FVECT dv; |
349 |
< |
double alt, azi; |
350 |
< |
{ |
351 |
< |
double d1, d2; |
352 |
< |
|
353 |
< |
d1 = sqrt(alt); |
354 |
< |
d2 = 2.*PI * azi; |
355 |
< |
dv[0] = d1*cos(d2); |
356 |
< |
dv[1] = d1*sin(d2); |
357 |
< |
dv[2] = sqrt(1. - alt); |
442 |
> |
return(1); |
443 |
|
} |