19 |
|
|
20 |
|
#include "random.h" |
21 |
|
|
22 |
+ |
#define MINSAMPLES 3 /* minimum number of pretest samples */ |
23 |
+ |
#define STESTMAX 30 /* maximum seeks per sample */ |
24 |
|
|
25 |
+ |
|
26 |
|
double getdisk(); |
27 |
|
|
28 |
|
static OBJECT *vobject; /* virtual source objects */ |
161 |
|
return(-1); /* at source!! */ |
162 |
|
if (source[sn].sflags & SPROX && d > source[sn].sl.prox) |
163 |
|
return(-1); /* too far away */ |
161 |
– |
ourspot.siz = 2.*PI*(1. - d/sqrt(d*d+maxrad2)); |
164 |
|
ourspot.flen = 0.; |
165 |
+ |
if (d*d > maxrad2) |
166 |
+ |
ourspot.siz = 2.*PI*(1. - sqrt(1.-maxrad2/(d*d))); |
167 |
+ |
else |
168 |
+ |
nsflags &= ~SSPOT; |
169 |
|
if (source[sn].sflags & SSPOT) { |
170 |
|
copystruct(&theirspot, source[sn].sl.s); |
171 |
|
multv3(theirspot.aim, source[sn].sl.s->aim, pm); |
172 |
< |
d = ourspot.siz; |
173 |
< |
if (!commonspot(&ourspot, &theirspot, nsloc)) |
174 |
< |
return(-1); /* no overlap */ |
172 |
> |
if (nsflags & SSPOT) { |
173 |
> |
ourspot.flen = theirspot.flen; |
174 |
> |
d = ourspot.siz; |
175 |
> |
if (!commonspot(&ourspot, &theirspot, nsloc)) |
176 |
> |
return(-1); /* no overlap */ |
177 |
> |
} else { |
178 |
> |
nsflags |= SSPOT; |
179 |
> |
copystruct(&ourspot, &theirspot); |
180 |
> |
d = 2.*ourspot.siz; |
181 |
> |
} |
182 |
|
if (ourspot.siz < d-FTINY) { /* it shrunk */ |
183 |
|
d = spotdisk(v, op, &ourspot, nsloc); |
184 |
|
if (d <= FTINY) |
188 |
|
VCOPY(ocent, v); |
189 |
|
} |
190 |
|
} |
178 |
– |
ourspot.flen = theirspot.flen; |
191 |
|
} |
192 |
|
if (source[sn].sflags & SFLAT) { /* behind source? */ |
193 |
|
multv3(nsnorm, source[sn].snorm, pm); |
194 |
< |
if (checkspot(&ourspot, nsnorm) < 0) |
194 |
> |
if (!checkspot(&ourspot, nsnorm)) |
195 |
|
return(-1); |
196 |
|
} |
197 |
|
} |
207 |
|
if (nsflags & SFLAT) |
208 |
|
VCOPY(source[i].snorm, nsnorm); |
209 |
|
source[i].ss = source[sn].ss; source[i].ss2 = source[sn].ss2; |
210 |
< |
if ((source[i].sl.s = (SPOT *)malloc(sizeof(SPOT))) == NULL) |
211 |
< |
goto memerr; |
212 |
< |
copystruct(source[i].sl.s, &ourspot); |
210 |
> |
if (nsflags & SSPOT) { |
211 |
> |
if ((source[i].sl.s = (SPOT *)malloc(sizeof(SPOT))) == NULL) |
212 |
> |
goto memerr; |
213 |
> |
copystruct(source[i].sl.s, &ourspot); |
214 |
> |
} |
215 |
|
if (nsflags & SPROX) |
216 |
|
source[i].sl.prox = source[sn].sl.prox; |
217 |
|
source[i].sa.svnext = sn; |
286 |
|
n = or2/DOT(offsdir,offsdir)*vspretest + .5; |
287 |
|
infront = DOT(onorm, offsdir) > 0.; |
288 |
|
} |
289 |
< |
if (n < 1) n = 1; |
289 |
> |
if (n < MINSAMPLES) n = MINSAMPLES; |
290 |
|
#ifdef DEBUG |
291 |
|
fprintf(stderr, "pretesting source %d in object %s with %d rays\n", |
292 |
|
sn, o->oname, n); |
293 |
|
#endif |
294 |
|
/* sample */ |
295 |
|
or = sqrt(or2); |
296 |
< |
ssn = 25*n; |
296 |
> |
ssn = STESTMAX*n; |
297 |
|
nhit = nok = 0; |
298 |
|
while (n-- > 0) { |
299 |
|
/* get sample point */ |