11 |
|
|
12 |
|
#include "ray.h" |
13 |
|
|
14 |
+ |
#include "octree.h" |
15 |
+ |
|
16 |
|
#include "otypes.h" |
17 |
|
|
18 |
|
#include "source.h" |
19 |
|
|
20 |
< |
#include "cone.h" |
20 |
> |
#include "random.h" |
21 |
|
|
22 |
< |
#include "face.h" |
22 |
> |
#define MINSAMPLES 3 /* minimum number of pretest samples */ |
23 |
> |
#define STESTMAX 30 /* maximum seeks per sample */ |
24 |
|
|
25 |
|
|
26 |
< |
double intercircle(); |
24 |
< |
SRCREC *makevsrc(); |
26 |
> |
double getdisk(); |
27 |
|
|
28 |
|
static OBJECT *vobject; /* virtual source objects */ |
29 |
|
static int nvobjects = 0; /* number of virtual source objects */ |
57 |
|
} |
58 |
|
if (nvobjects == 0) |
59 |
|
return; |
60 |
+ |
#ifdef DEBUG |
61 |
+ |
fprintf(stderr, "found %d virtual source objects\n", nvobjects); |
62 |
+ |
#endif |
63 |
|
/* append virtual sources */ |
64 |
|
for (i = nsources; i-- > 0; ) |
65 |
< |
if (!(source[i].sflags & SSKIP)) |
61 |
< |
addvirtuals(&source[i], directrelay); |
65 |
> |
addvirtuals(i, directrelay); |
66 |
|
/* done with our object list */ |
67 |
|
free((char *)vobject); |
68 |
|
nvobjects = 0; |
69 |
|
} |
70 |
|
|
71 |
|
|
72 |
< |
addvirtuals(sr, nr) /* add virtual sources associated with sr */ |
73 |
< |
SRCREC *sr; |
72 |
> |
addvirtuals(sn, nr) /* add virtuals associated with source */ |
73 |
> |
int sn; |
74 |
|
int nr; |
75 |
|
{ |
76 |
|
register int i; |
77 |
|
/* check relay limit first */ |
78 |
|
if (nr <= 0) |
79 |
|
return; |
80 |
+ |
if (source[sn].sflags & SSKIP) |
81 |
+ |
return; |
82 |
|
/* check each virtual object for projection */ |
83 |
|
for (i = 0; i < nvobjects; i++) |
84 |
|
/* vproject() calls us recursively */ |
85 |
< |
vproject(objptr(i), sr, nr-1); |
85 |
> |
vproject(objptr(vobject[i]), sn, nr-1); |
86 |
|
} |
87 |
|
|
88 |
|
|
89 |
< |
vproject(o, s, n) /* create projected source(s) if they exist */ |
89 |
> |
vproject(o, sn, n) /* create projected source(s) if they exist */ |
90 |
|
OBJREC *o; |
91 |
< |
SRCREC *s; |
91 |
> |
int sn; |
92 |
|
int n; |
93 |
|
{ |
94 |
|
register int i; |
95 |
|
register VSMATERIAL *vsmat; |
96 |
|
MAT4 proj; |
97 |
< |
SRCREC *ns; |
97 |
> |
int ns; |
98 |
> |
|
99 |
> |
if (o == source[sn].so) /* objects cannot project themselves */ |
100 |
> |
return; |
101 |
|
/* get virtual source material */ |
102 |
|
vsmat = sfun[objptr(o->omod)->otype].mf; |
103 |
|
/* project virtual sources */ |
104 |
|
for (i = 0; i < vsmat->nproj; i++) |
105 |
< |
if ((*vsmat->vproj)(proj, o, s, i)) |
106 |
< |
if ((ns = makevsrc(o, s, proj)) != NULL) |
105 |
> |
if ((*vsmat->vproj)(proj, o, &source[sn], i)) |
106 |
> |
if ((ns = makevsrc(o, sn, proj)) >= 0) { |
107 |
> |
#ifdef DEBUG |
108 |
> |
virtverb(ns, stderr); |
109 |
> |
#endif |
110 |
|
addvirtuals(ns, n); |
111 |
+ |
} |
112 |
|
} |
113 |
|
|
114 |
|
|
115 |
< |
SRCREC * |
116 |
< |
makevsrc(op, sp, pm) /* make virtual source if reasonable */ |
115 |
> |
int |
116 |
> |
makevsrc(op, sn, pm) /* make virtual source if reasonable */ |
117 |
|
OBJREC *op; |
118 |
< |
register SRCREC *sp; |
118 |
> |
register int sn; |
119 |
|
MAT4 pm; |
120 |
|
{ |
121 |
< |
register SRCREC *newsrc; |
122 |
< |
FVECT nsloc, ocent, nsnorm; |
121 |
> |
FVECT nsloc, nsnorm, ocent, v; |
122 |
> |
double maxrad2, d; |
123 |
|
int nsflags; |
111 |
– |
double maxrad2; |
112 |
– |
double d1; |
124 |
|
SPOT theirspot, ourspot; |
125 |
|
register int i; |
126 |
|
|
127 |
< |
nsflags = (sp->sflags|(SVIRTUAL|SFOLLOW)) & ~SSPOT; |
127 |
> |
nsflags = source[sn].sflags | (SVIRTUAL|SSPOT|SFOLLOW); |
128 |
|
/* get object center and max. radius */ |
129 |
< |
if (sfun[op->otype].of->getdisk != NULL) { |
130 |
< |
maxrad2 = (*sfun[op->otype].of->getdisk)(ocent, op); |
131 |
< |
if (maxrad2 <= FTINY) /* too small? */ |
121 |
< |
return(NULL); |
122 |
< |
nsflags |= SSPOT; |
123 |
< |
} |
129 |
> |
maxrad2 = getdisk(ocent, op, sn); |
130 |
> |
if (maxrad2 <= FTINY) /* too small? */ |
131 |
> |
return(-1); |
132 |
|
/* get location and spot */ |
133 |
< |
if (sp->sflags & SDISTANT) { /* distant source */ |
134 |
< |
if (sp->sflags & SPROX) |
135 |
< |
return(NULL); /* should never get here! */ |
136 |
< |
multv3(nsloc, sp->sloc, pm); |
137 |
< |
if (nsflags & SSPOT) { |
138 |
< |
VCOPY(ourspot.aim, ocent); |
139 |
< |
ourspot.siz = PI*maxrad2; |
140 |
< |
ourspot.flen = 0.; |
133 |
> |
if (source[sn].sflags & SDISTANT) { /* distant source */ |
134 |
> |
if (source[sn].sflags & SPROX) |
135 |
> |
return(-1); /* should never get here! */ |
136 |
> |
multv3(nsloc, source[sn].sloc, pm); |
137 |
> |
VCOPY(ourspot.aim, ocent); |
138 |
> |
ourspot.siz = PI*maxrad2; |
139 |
> |
ourspot.flen = 0.; |
140 |
> |
if (source[sn].sflags & SSPOT) { |
141 |
> |
copystruct(&theirspot, source[sn].sl.s); |
142 |
> |
multp3(theirspot.aim, source[sn].sl.s->aim, pm); |
143 |
> |
d = ourspot.siz; |
144 |
> |
if (!commonbeam(&ourspot, &theirspot, nsloc)) |
145 |
> |
return(-1); /* no overlap */ |
146 |
> |
if (ourspot.siz < d-FTINY) { /* it shrunk */ |
147 |
> |
d = beamdisk(v, op, &ourspot, nsloc); |
148 |
> |
if (d <= FTINY) |
149 |
> |
return(-1); |
150 |
> |
if (d < maxrad2) { |
151 |
> |
maxrad2 = d; |
152 |
> |
VCOPY(ocent, v); |
153 |
> |
} |
154 |
> |
} |
155 |
|
} |
134 |
– |
if (sp->sflags & SSPOT) { |
135 |
– |
copystruct(&theirspot, sp->sl.s); |
136 |
– |
multp3(theirspot.aim, sp->sl.s->aim, pm); |
137 |
– |
if (nsflags & SSPOT && |
138 |
– |
!commonbeam(&ourspot, &theirspot, nsloc)) |
139 |
– |
return(NULL); /* no overlap */ |
140 |
– |
} |
156 |
|
} else { /* local source */ |
157 |
< |
multp3(nsloc, sp->sloc, pm); |
158 |
< |
if (nsflags & SSPOT) { |
159 |
< |
for (i = 0; i < 3; i++) |
160 |
< |
ourspot.aim[i] = ocent[i] - nsloc[i]; |
161 |
< |
if ((d1 = normalize(ourspot.aim)) == 0.) |
162 |
< |
return(NULL); /* at source!! */ |
163 |
< |
if (sp->sflags & SPROX && d1 > sp->sl.prox) |
164 |
< |
return(NULL); /* too far away */ |
165 |
< |
ourspot.siz = 2.*PI*(1. - d1/sqrt(d1*d1+maxrad2)); |
166 |
< |
ourspot.flen = 0.; |
167 |
< |
} else if (sp->sflags & SPROX) { |
168 |
< |
FVECT norm; |
169 |
< |
double offs; |
170 |
< |
/* use distance from plane */ |
171 |
< |
offs = (*sfun[op->otype].of->getpleq)(norm, op); |
172 |
< |
d1 = DOT(norm, nsloc) - offs; |
173 |
< |
if (d1 > sp->sl.prox || d1 < -sp->sl.prox) |
174 |
< |
return(NULL); /* too far away */ |
175 |
< |
} |
176 |
< |
if (sp->sflags & SSPOT) { |
177 |
< |
copystruct(&theirspot, sp->sl.s); |
178 |
< |
multv3(theirspot.aim, sp->sl.s->aim, pm); |
179 |
< |
if (nsflags & SSPOT) { |
165 |
< |
if (!commonspot(&ourspot, &theirspot, nsloc)) |
166 |
< |
return(NULL); /* no overlap */ |
167 |
< |
ourspot.flen = theirspot.flen; |
157 |
> |
multp3(nsloc, source[sn].sloc, pm); |
158 |
> |
for (i = 0; i < 3; i++) |
159 |
> |
ourspot.aim[i] = ocent[i] - nsloc[i]; |
160 |
> |
if ((d = normalize(ourspot.aim)) == 0.) |
161 |
> |
return(-1); /* at source!! */ |
162 |
> |
if (source[sn].sflags & SPROX && d > source[sn].sl.prox) |
163 |
> |
return(-1); /* too far away */ |
164 |
> |
ourspot.siz = 2.*PI*(1. - d/sqrt(d*d+maxrad2)); |
165 |
> |
ourspot.flen = 0.; |
166 |
> |
if (source[sn].sflags & SSPOT) { |
167 |
> |
copystruct(&theirspot, source[sn].sl.s); |
168 |
> |
multv3(theirspot.aim, source[sn].sl.s->aim, pm); |
169 |
> |
d = ourspot.siz; |
170 |
> |
if (!commonspot(&ourspot, &theirspot, nsloc)) |
171 |
> |
return(-1); /* no overlap */ |
172 |
> |
if (ourspot.siz < d-FTINY) { /* it shrunk */ |
173 |
> |
d = spotdisk(v, op, &ourspot, nsloc); |
174 |
> |
if (d <= FTINY) |
175 |
> |
return(-1); |
176 |
> |
if (d < maxrad2) { |
177 |
> |
maxrad2 = d; |
178 |
> |
VCOPY(ocent, v); |
179 |
> |
} |
180 |
|
} |
181 |
+ |
ourspot.flen = theirspot.flen; |
182 |
|
} |
183 |
< |
if (sp->sflags & SFLAT) { /* check for behind source */ |
184 |
< |
multv3(nsnorm, sp->snorm, pm); |
185 |
< |
if (nsflags & SSPOT && checkspot(&ourspot, nsnorm) < 0) |
186 |
< |
return(NULL); |
183 |
> |
if (source[sn].sflags & SFLAT) { /* behind source? */ |
184 |
> |
multv3(nsnorm, source[sn].snorm, pm); |
185 |
> |
if (!checkspot(&ourspot, nsnorm)) |
186 |
> |
return(-1); |
187 |
|
} |
188 |
|
} |
189 |
< |
/* everything is OK, make source */ |
190 |
< |
if ((newsrc = newsource()) == NULL) |
189 |
> |
/* pretest visibility */ |
190 |
> |
nsflags = vstestvis(nsflags, op, ocent, maxrad2, sn); |
191 |
> |
if (nsflags & SSKIP) |
192 |
> |
return(-1); /* obstructed */ |
193 |
> |
/* it all checks out, so make it */ |
194 |
> |
if ((i = newsource()) < 0) |
195 |
|
goto memerr; |
196 |
< |
newsrc->sflags = nsflags; |
197 |
< |
VCOPY(newsrc->sloc, nsloc); |
196 |
> |
source[i].sflags = nsflags; |
197 |
> |
VCOPY(source[i].sloc, nsloc); |
198 |
|
if (nsflags & SFLAT) |
199 |
< |
VCOPY(newsrc->snorm, nsnorm); |
200 |
< |
newsrc->ss = sp->ss; newsrc->ss2 = sp->ss2; |
201 |
< |
if ((nsflags | sp->sflags) & SSPOT) { |
202 |
< |
if ((newsrc->sl.s = (SPOT *)malloc(sizeof(SPOT))) == NULL) |
203 |
< |
goto memerr; |
187 |
< |
if (nsflags & SSPOT) |
188 |
< |
copystruct(newsrc->sl.s, &ourspot); |
189 |
< |
else |
190 |
< |
copystruct(newsrc->sl.s, &theirspot); |
191 |
< |
newsrc->sflags |= SSPOT; |
192 |
< |
} |
199 |
> |
VCOPY(source[i].snorm, nsnorm); |
200 |
> |
source[i].ss = source[sn].ss; source[i].ss2 = source[sn].ss2; |
201 |
> |
if ((source[i].sl.s = (SPOT *)malloc(sizeof(SPOT))) == NULL) |
202 |
> |
goto memerr; |
203 |
> |
copystruct(source[i].sl.s, &ourspot); |
204 |
|
if (nsflags & SPROX) |
205 |
< |
newsrc->sl.prox = sp->sl.prox; |
206 |
< |
newsrc->sa.svnext = sp - source; |
207 |
< |
return(newsrc); |
205 |
> |
source[i].sl.prox = source[sn].sl.prox; |
206 |
> |
source[i].sa.svnext = sn; |
207 |
> |
source[i].so = op; |
208 |
> |
return(i); |
209 |
|
memerr: |
210 |
|
error(SYSTEM, "out of memory in makevsrc"); |
211 |
|
} |
212 |
|
|
213 |
|
|
214 |
< |
commonspot(sp1, sp2, org) /* set sp1 to intersection of sp1 and sp2 */ |
215 |
< |
register SPOT *sp1, *sp2; |
216 |
< |
FVECT org; |
214 |
> |
double |
215 |
> |
getdisk(oc, op, sn) /* get visible object disk */ |
216 |
> |
FVECT oc; |
217 |
> |
OBJREC *op; |
218 |
> |
register int sn; |
219 |
|
{ |
220 |
< |
FVECT cent; |
221 |
< |
double rad2, cos1, cos2; |
222 |
< |
|
223 |
< |
cos1 = 1. - sp1->siz/(2.*PI); |
224 |
< |
cos2 = 1. - sp2->siz/(2.*PI); |
225 |
< |
if (sp2->siz >= 2.*PI-FTINY) /* BIG, just check overlap */ |
226 |
< |
return(DOT(sp1->aim,sp2->aim) >= cos1*cos2 - |
227 |
< |
sqrt((1.-cos1*cos1)*(1.-cos2*cos2))); |
228 |
< |
/* compute and check disks */ |
229 |
< |
rad2 = intercircle(cent, sp1->aim, sp2->aim, |
230 |
< |
1./(cos1*cos1) - 1., 1./(cos2*cos2) - 1.); |
231 |
< |
if (rad2 <= FTINY || normalize(cent) == 0.) |
232 |
< |
return(0); |
233 |
< |
VCOPY(sp1->aim, cent); |
234 |
< |
sp1->siz = 2.*PI*(1. - 1./sqrt(1.+rad2)); |
235 |
< |
return(1); |
220 |
> |
double rad2, roffs, offs, d, rd, rdoto; |
221 |
> |
FVECT rnrm, nrm; |
222 |
> |
/* first, use object getdisk function */ |
223 |
> |
rad2 = getmaxdisk(oc, op); |
224 |
> |
if (!(source[sn].sflags & SVIRTUAL)) |
225 |
> |
return(rad2); /* all done for normal source */ |
226 |
> |
/* check for correct side of relay surface */ |
227 |
> |
roffs = getplaneq(rnrm, source[sn].so); |
228 |
> |
rd = DOT(rnrm, source[sn].sloc); /* source projection */ |
229 |
> |
if (!(source[sn].sflags & SDISTANT)) |
230 |
> |
rd -= roffs; |
231 |
> |
d = DOT(rnrm, oc) - roffs; /* disk distance to relay plane */ |
232 |
> |
if ((d > 0.) ^ (rd > 0.)) |
233 |
> |
return(rad2); /* OK if opposite sides */ |
234 |
> |
if (d*d >= rad2) |
235 |
> |
return(0.); /* no relay is possible */ |
236 |
> |
/* we need a closer look */ |
237 |
> |
offs = getplaneq(nrm, op); |
238 |
> |
rdoto = DOT(rnrm, nrm); |
239 |
> |
if (d*d >= rad2*(1.-rdoto*rdoto)) |
240 |
> |
return(0.); /* disk entirely on projection side */ |
241 |
> |
/* should shrink disk but I'm lazy */ |
242 |
> |
return(rad2); |
243 |
|
} |
244 |
|
|
245 |
|
|
246 |
< |
commonbeam(sp1, sp2, dir) /* set sp1 to intersection of sp1 and sp2 */ |
247 |
< |
register SPOT *sp1, *sp2; |
248 |
< |
FVECT dir; |
246 |
> |
int |
247 |
> |
vstestvis(f, o, oc, or2, sn) /* pretest source visibility */ |
248 |
> |
int f; /* virtual source flags */ |
249 |
> |
OBJREC *o; /* relay object */ |
250 |
> |
FVECT oc; /* relay object center */ |
251 |
> |
double or2; /* relay object radius squared */ |
252 |
> |
register int sn; /* target source number */ |
253 |
|
{ |
254 |
< |
FVECT cent, c1, c2; |
255 |
< |
double rad2, d; |
256 |
< |
register int i; |
257 |
< |
/* move centers to common plane */ |
258 |
< |
d = DOT(sp1->aim, dir); |
259 |
< |
for (i = 0; i < 3; i++) |
260 |
< |
c1[i] = sp1->aim[i] - d*dir[i]; |
261 |
< |
d = DOT(sp2->aim, dir); |
262 |
< |
for (i = 0; i < 3; i++) |
263 |
< |
c2[i] = sp2->aim[i] - d*dir[i]; |
264 |
< |
/* compute overlap */ |
265 |
< |
rad2 = intercircle(cent, c1, c2, sp1->siz/PI, sp2->siz/PI); |
266 |
< |
if (rad2 <= FTINY) |
267 |
< |
return(0); |
268 |
< |
VCOPY(sp1->aim, cent); |
269 |
< |
sp1->siz = PI*rad2; |
270 |
< |
return(1); |
254 |
> |
RAY sr; |
255 |
> |
FVECT onorm; |
256 |
> |
FVECT offsdir; |
257 |
> |
double or, d; |
258 |
> |
int infront; |
259 |
> |
int ssn; |
260 |
> |
int nhit, nok; |
261 |
> |
register int i, n; |
262 |
> |
/* return if pretesting disabled */ |
263 |
> |
if (vspretest <= 0) |
264 |
> |
return(f); |
265 |
> |
/* get surface normal */ |
266 |
> |
getplaneq(onorm, o); |
267 |
> |
/* set number of rays to sample */ |
268 |
> |
if (source[sn].sflags & SDISTANT) { |
269 |
> |
n = (2./3.*PI*PI)*or2/(thescene.cusize*thescene.cusize)* |
270 |
> |
vspretest + .5; |
271 |
> |
infront = DOT(onorm, source[sn].sloc) > 0.; |
272 |
> |
} else { |
273 |
> |
for (i = 0; i < 3; i++) |
274 |
> |
offsdir[i] = source[sn].sloc[i] - oc[i]; |
275 |
> |
n = or2/DOT(offsdir,offsdir)*vspretest + .5; |
276 |
> |
infront = DOT(onorm, offsdir) > 0.; |
277 |
> |
} |
278 |
> |
if (n < MINSAMPLES) n = MINSAMPLES; |
279 |
> |
#ifdef DEBUG |
280 |
> |
fprintf(stderr, "pretesting source %d in object %s with %d rays\n", |
281 |
> |
sn, o->oname, n); |
282 |
> |
#endif |
283 |
> |
/* sample */ |
284 |
> |
or = sqrt(or2); |
285 |
> |
ssn = STESTMAX*n; |
286 |
> |
nhit = nok = 0; |
287 |
> |
while (n-- > 0) { |
288 |
> |
/* get sample point */ |
289 |
> |
do { |
290 |
> |
if (--ssn < 0) { |
291 |
> |
#ifdef DEBUG |
292 |
> |
fprintf(stderr, "\ttoo hard to hit\n"); |
293 |
> |
#endif |
294 |
> |
return(f); /* too small a target! */ |
295 |
> |
} |
296 |
> |
for (i = 0; i < 3; i++) |
297 |
> |
offsdir[i] = or*(1. - |
298 |
> |
2.*urand(931*i+5827+ssn)); |
299 |
> |
for (i = 0; i < 3; i++) |
300 |
> |
sr.rorg[i] = oc[i] + offsdir[i]; |
301 |
> |
d = DOT(offsdir,onorm); |
302 |
> |
if (infront) |
303 |
> |
for (i = 0; i < 3; i++) { |
304 |
> |
sr.rorg[i] -= (d-.0001)*onorm[i]; |
305 |
> |
sr.rdir[i] = -onorm[i]; |
306 |
> |
} |
307 |
> |
else |
308 |
> |
for (i = 0; i < 3; i++) { |
309 |
> |
sr.rorg[i] -= (d+.0001)*onorm[i]; |
310 |
> |
sr.rdir[i] = onorm[i]; |
311 |
> |
} |
312 |
> |
rayorigin(&sr, NULL, PRIMARY, 1.0); |
313 |
> |
} while (!(*ofun[o->otype].funp)(o, &sr)); |
314 |
> |
/* check against source */ |
315 |
> |
samplendx++; |
316 |
> |
if (srcray(&sr, NULL, sn) == 0.) |
317 |
> |
continue; |
318 |
> |
sr.revf = srcvalue; |
319 |
> |
rayvalue(&sr); |
320 |
> |
if (bright(sr.rcol) <= FTINY) |
321 |
> |
continue; |
322 |
> |
nok++; |
323 |
> |
/* check against obstructions */ |
324 |
> |
srcray(&sr, NULL, sn); |
325 |
> |
rayvalue(&sr); |
326 |
> |
if (bright(sr.rcol) > FTINY) |
327 |
> |
nhit++; |
328 |
> |
if (nhit > 0 && nhit < nok) { |
329 |
> |
#ifdef DEBUG |
330 |
> |
fprintf(stderr, "\tpartially occluded\n"); |
331 |
> |
#endif |
332 |
> |
return(f); /* need to shadow test */ |
333 |
> |
} |
334 |
> |
} |
335 |
> |
if (nhit == 0) { |
336 |
> |
#ifdef DEBUG |
337 |
> |
fprintf(stderr, "\t0%% hit rate\n"); |
338 |
> |
#endif |
339 |
> |
return(f | SSKIP); /* 0% hit rate: totally occluded */ |
340 |
> |
} |
341 |
> |
#ifdef DEBUG |
342 |
> |
fprintf(stderr, "\t100%% hit rate\n"); |
343 |
> |
#endif |
344 |
> |
return(f & ~SFOLLOW); /* 100% hit rate: no occlusion */ |
345 |
|
} |
346 |
+ |
|
347 |
|
|
348 |
< |
|
349 |
< |
checkspot(sp, nrm) /* check spotlight for behind source */ |
350 |
< |
register SPOT *sp; |
351 |
< |
FVECT nrm; |
348 |
> |
#ifdef DEBUG |
349 |
> |
virtverb(sn, fp) /* print verbose description of virtual source */ |
350 |
> |
register int sn; |
351 |
> |
FILE *fp; |
352 |
|
{ |
253 |
– |
double d, d1; |
254 |
– |
|
255 |
– |
d = DOT(sp->aim, nrm); |
256 |
– |
if (d > FTINY) /* center in front? */ |
257 |
– |
return(0); |
258 |
– |
/* else check horizon */ |
259 |
– |
d1 = 1. - sp->siz/(2.*PI); |
260 |
– |
return(1.-FTINY-d*d > d1*d1); |
261 |
– |
} |
262 |
– |
|
263 |
– |
|
264 |
– |
double |
265 |
– |
intercircle(cc, c1, c2, r1s, r2s) /* intersect two circles */ |
266 |
– |
FVECT cc; /* midpoint (return value) */ |
267 |
– |
FVECT c1, c2; /* circle centers */ |
268 |
– |
double r1s, r2s; /* radii squared */ |
269 |
– |
{ |
270 |
– |
double a2, d2, l; |
271 |
– |
FVECT disp; |
353 |
|
register int i; |
354 |
|
|
355 |
< |
for (i = 0; i < 3; i++) |
356 |
< |
disp[i] = c2[i] - c1[i]; |
357 |
< |
d2 = DOT(disp,disp); |
358 |
< |
/* circle within overlap? */ |
359 |
< |
if (r1s < r2s) { |
360 |
< |
if (r2s >= r1s + d2) { |
361 |
< |
VCOPY(cc, c1); |
362 |
< |
return(r1s); |
363 |
< |
} |
364 |
< |
} else { |
365 |
< |
if (r1s >= r2s + d2) { |
366 |
< |
VCOPY(cc, c2); |
367 |
< |
return(r2s); |
368 |
< |
} |
369 |
< |
} |
370 |
< |
a2 = .25*(2.*(r1s+r2s) - d2 - (r2s-r1s)*(r2s-r1s)/d2); |
371 |
< |
/* no overlap? */ |
291 |
< |
if (a2 <= 0.) |
292 |
< |
return(0.); |
293 |
< |
/* overlap, compute center */ |
294 |
< |
l = sqrt((r1s - a2)/d2); |
295 |
< |
for (i = 0; i < 3; i++) |
296 |
< |
cc[i] = c1[i] + l*disp[i]; |
297 |
< |
return(a2); |
355 |
> |
fprintf(fp, "%s virtual source %d in %s %s\n", |
356 |
> |
source[sn].sflags & SDISTANT ? "distant" : "local", |
357 |
> |
sn, ofun[source[sn].so->otype].funame, |
358 |
> |
source[sn].so->oname); |
359 |
> |
fprintf(fp, "\tat (%f,%f,%f)\n", |
360 |
> |
source[sn].sloc[0], source[sn].sloc[1], source[sn].sloc[2]); |
361 |
> |
fprintf(fp, "\tlinked to source %d (%s)\n", |
362 |
> |
source[sn].sa.svnext, source[source[sn].sa.svnext].so->oname); |
363 |
> |
if (source[sn].sflags & SFOLLOW) |
364 |
> |
fprintf(fp, "\talways followed\n"); |
365 |
> |
else |
366 |
> |
fprintf(fp, "\tnever followed\n"); |
367 |
> |
if (!(source[sn].sflags & SSPOT)) |
368 |
> |
return; |
369 |
> |
fprintf(fp, "\twith spot aim (%f,%f,%f) and size %f\n", |
370 |
> |
source[sn].sl.s->aim[0], source[sn].sl.s->aim[1], |
371 |
> |
source[sn].sl.s->aim[2], source[sn].sl.s->siz); |
372 |
|
} |
373 |
+ |
#endif |