26 |
|
sprintf(errmsg, "(%s): cannot make illum for %s \"%s\"", |
27 |
|
nm, ofun[ob->otype].funame, ob->oname); |
28 |
|
error(WARNING, errmsg); |
29 |
< |
if (!(il->flags & IL_LIGHT)) |
30 |
< |
printobj(il->altmat, ob); |
29 |
> |
printobj(il->altmat, ob); |
30 |
|
} |
31 |
|
|
32 |
|
|
55 |
|
return; |
56 |
|
} |
57 |
|
/* set up sampling */ |
58 |
< |
n = PI * il->sampdens; |
59 |
< |
nalt = sqrt(n/PI) + .5; |
60 |
< |
nazi = PI*nalt + .5; |
58 |
> |
if (il->sampdens <= 0) |
59 |
> |
nalt = nazi = 1; |
60 |
> |
else { |
61 |
> |
n = PI * il->sampdens; |
62 |
> |
nalt = sqrt(n/PI) + .5; |
63 |
> |
nazi = PI*nalt + .5; |
64 |
> |
} |
65 |
|
n = nalt*nazi; |
66 |
|
distarr = (float *)calloc(n, 3*sizeof(float)); |
67 |
|
if (distarr == NULL) |
68 |
|
error(SYSTEM, "out of memory in o_face"); |
69 |
< |
mkaxes(u, v, fa->norm); |
69 |
> |
/* take first edge longer than sqrt(area) */ |
70 |
> |
for (j = fa->nv-1, i = 0; i < fa->nv; j = i++) { |
71 |
> |
u[0] = VERTEX(fa,i)[0] - VERTEX(fa,j)[0]; |
72 |
> |
u[1] = VERTEX(fa,i)[1] - VERTEX(fa,j)[1]; |
73 |
> |
u[2] = VERTEX(fa,i)[2] - VERTEX(fa,j)[2]; |
74 |
> |
if (DOT(u,u) >= fa->area-FTINY) |
75 |
> |
break; |
76 |
> |
} |
77 |
> |
if (i < fa->nv) { /* got one! -- let's align our axes */ |
78 |
> |
normalize(u); |
79 |
> |
fcross(v, fa->norm, u); |
80 |
> |
} else /* oh well, we'll just have to wing it */ |
81 |
> |
mkaxes(u, v, fa->norm); |
82 |
> |
/* now, find limits in (u,v) coordinates */ |
83 |
|
ur[0] = vr[0] = FHUGE; |
84 |
|
ur[1] = vr[1] = -FHUGE; |
85 |
|
for (i = 0; i < fa->nv; i++) { |
98 |
|
for (i = 0; i < il->nsamps; i++) { |
99 |
|
/* random direction */ |
100 |
|
h = ilhash(dim, 3) + i; |
101 |
< |
peano(sp, 2, urand(h), .02); |
101 |
> |
multisamp(sp, 2, urand(h)); |
102 |
|
r1 = (dim[1] + sp[0])/nalt; |
103 |
< |
r2 = (dim[2] + sp[1])/nazi; |
103 |
> |
r2 = (dim[2] + sp[1] - .5)/nazi; |
104 |
|
flatdir(dn, r1, r2); |
105 |
|
for (j = 0; j < 3; j++) |
106 |
|
dir[j] = -dn[0]*u[j] - dn[1]*v[j] - dn[2]*fa->norm[j]; |
107 |
|
/* random location */ |
108 |
|
do { |
109 |
< |
peano(sp, 2, urand(h+nmisses), .01); |
109 |
> |
multisamp(sp, 2, urand(h+4862+nmisses)); |
110 |
|
r1 = ur[0] + (ur[1]-ur[0]) * sp[0]; |
111 |
|
r2 = vr[0] + (vr[1]-vr[0]) * sp[1]; |
112 |
|
for (j = 0; j < 3; j++) |
127 |
|
raysamp(distarr+3*(dim[1]*nazi+dim[2]), org, dir, rt); |
128 |
|
} |
129 |
|
rayflush(rt); |
130 |
< |
/* write out the face w/ distribution */ |
131 |
< |
flatout(il, distarr, nalt, nazi, u, v, fa->norm); |
132 |
< |
illumout(il, ob); |
130 |
> |
/* write out the face and its distribution */ |
131 |
> |
if (average(il, distarr, nalt*nazi)) { |
132 |
> |
if (il->sampdens > 0) |
133 |
> |
flatout(il, distarr, nalt, nazi, u, v, fa->norm); |
134 |
> |
illumout(il, ob); |
135 |
> |
} else |
136 |
> |
printobj(il->altmat, ob); |
137 |
|
/* clean up */ |
138 |
|
freeface(ob); |
139 |
|
free((char *)distarr); |
158 |
|
if (ob->oargs.nfargs != 4) |
159 |
|
objerror(ob, USER, "bad # of arguments"); |
160 |
|
/* set up sampling */ |
161 |
< |
n = 4.*PI * il->sampdens; |
162 |
< |
nalt = sqrt(n/PI) + .5; |
163 |
< |
nazi = PI*nalt + .5; |
161 |
> |
if (il->sampdens <= 0) |
162 |
> |
nalt = nazi = 1; |
163 |
> |
else { |
164 |
> |
n = 4.*PI * il->sampdens; |
165 |
> |
nalt = sqrt(n/PI) + .5; |
166 |
> |
nazi = PI*nalt + .5; |
167 |
> |
} |
168 |
|
n = nalt*nazi; |
169 |
|
distarr = (float *)calloc(n, 3*sizeof(float)); |
170 |
|
if (distarr == NULL) |
175 |
|
for (dim[2] = 0; dim[2] < nazi; dim[2]++) |
176 |
|
for (i = 0; i < il->nsamps; i++) { |
177 |
|
/* next sample point */ |
178 |
< |
peano(sp, 4, urand(ilhash(dim,3)+i), .02); |
178 |
> |
multisamp(sp, 4, urand(ilhash(dim,3)+i)); |
179 |
|
/* random direction */ |
180 |
|
r1 = (dim[1] + sp[0])/nalt; |
181 |
< |
r2 = (dim[2] + sp[1])/nazi; |
181 |
> |
r2 = (dim[2] + sp[1] - .5)/nazi; |
182 |
|
rounddir(dir, r1, r2); |
183 |
|
/* random location */ |
184 |
|
mkaxes(u, v, dir); /* yuck! */ |
196 |
|
raysamp(distarr+3*(dim[1]*nazi+dim[2]), org, dir, rt); |
197 |
|
} |
198 |
|
rayflush(rt); |
199 |
< |
/* write out the sphere w/ distribution */ |
200 |
< |
roundout(il, distarr, nalt, nazi); |
201 |
< |
illumout(il, ob); |
199 |
> |
/* write out the sphere and its distribution */ |
200 |
> |
if (average(il, distarr, nalt*nazi)) { |
201 |
> |
if (il->sampdens > 0) |
202 |
> |
roundout(il, distarr, nalt, nazi); |
203 |
> |
else |
204 |
> |
objerror(ob, WARNING, "diffuse distribution"); |
205 |
> |
illumout(il, ob); |
206 |
> |
} else |
207 |
> |
printobj(il->altmat, ob); |
208 |
|
/* clean up */ |
209 |
|
free((char *)distarr); |
210 |
|
} |
227 |
|
/* get/check arguments */ |
228 |
|
co = getcone(ob, 0); |
229 |
|
/* set up sampling */ |
230 |
< |
n = PI * il->sampdens; |
231 |
< |
nalt = sqrt(n/PI) + .5; |
232 |
< |
nazi = PI*nalt + .5; |
230 |
> |
if (il->sampdens <= 0) |
231 |
> |
nalt = nazi = 1; |
232 |
> |
else { |
233 |
> |
n = PI * il->sampdens; |
234 |
> |
nalt = sqrt(n/PI) + .5; |
235 |
> |
nazi = PI*nalt + .5; |
236 |
> |
} |
237 |
|
n = nalt*nazi; |
238 |
|
distarr = (float *)calloc(n, 3*sizeof(float)); |
239 |
|
if (distarr == NULL) |
245 |
|
for (dim[2] = 0; dim[2] < nazi; dim[2]++) |
246 |
|
for (i = 0; i < il->nsamps; i++) { |
247 |
|
/* next sample point */ |
248 |
< |
peano(sp, 4, urand(ilhash(dim,3)+i), .02); |
248 |
> |
multisamp(sp, 4, urand(ilhash(dim,3)+i)); |
249 |
|
/* random direction */ |
250 |
|
r1 = (dim[1] + sp[0])/nalt; |
251 |
< |
r2 = (dim[2] + sp[1])/nalt; |
251 |
> |
r2 = (dim[2] + sp[1] - .5)/nazi; |
252 |
|
flatdir(dn, r1, r2); |
253 |
|
for (j = 0; j < 3; j++) |
254 |
|
dir[j] = -dn[0]*u[j] - dn[1]*v[j] - dn[2]*co->ad[j]; |
266 |
|
raysamp(distarr+3*(dim[1]*nazi+dim[2]), org, dir, rt); |
267 |
|
} |
268 |
|
rayflush(rt); |
269 |
< |
/* write out the ring w/ distribution */ |
270 |
< |
flatout(il, distarr, nalt, nazi, u, v, co->ad); |
271 |
< |
illumout(il, ob); |
269 |
> |
/* write out the ring and its distribution */ |
270 |
> |
if (average(il, distarr, nalt*nazi)) { |
271 |
> |
if (il->sampdens > 0) |
272 |
> |
flatout(il, distarr, nalt, nazi, u, v, co->ad); |
273 |
> |
illumout(il, ob); |
274 |
> |
} else |
275 |
> |
printobj(il->altmat, ob); |
276 |
|
/* clean up */ |
277 |
|
freecone(ob); |
278 |
|
free((char *)distarr); |
303 |
|
if (rt->nrays <= 0) |
304 |
|
return; |
305 |
|
bzero(rt->buf+6*rt->nrays, 6*sizeof(float)); |
306 |
+ |
errno = 0; |
307 |
|
if ( process(rt->pd, (char *)rt->buf, (char *)rt->buf, |
308 |
|
3*sizeof(float)*rt->nrays, |
309 |
|
6*sizeof(float)*(rt->nrays+1)) < |