21 |
|
#define MINSAMPLES 16 /* minimum number of pretest samples */ |
22 |
|
#define STESTMAX 32 /* maximum seeks per sample */ |
23 |
|
|
24 |
+ |
#define FEQ(a,b) ((a)-(b)+FTINY >= 0 && (b)-(a)+FTINY >= 0) |
25 |
|
|
26 |
+ |
|
27 |
|
static OBJECT *vobject; /* virtual source objects */ |
28 |
|
static int nvobjects = 0; /* number of virtual source objects */ |
29 |
|
|
30 |
|
|
31 |
< |
extern void |
31 |
> |
static int |
32 |
> |
isident4(MAT4 m) |
33 |
> |
{ |
34 |
> |
int i, j; |
35 |
> |
|
36 |
> |
for (i = 4; i--; ) |
37 |
> |
for (j = 4; j--; ) |
38 |
> |
if (!FEQ(m[i][j], i==j)) |
39 |
> |
return(0); |
40 |
> |
return(1); |
41 |
> |
} |
42 |
> |
|
43 |
> |
|
44 |
> |
void |
45 |
|
markvirtuals(void) /* find and mark virtual sources */ |
46 |
|
{ |
47 |
< |
register OBJREC *o; |
48 |
< |
register int i; |
47 |
> |
OBJREC *o; |
48 |
> |
int i; |
49 |
|
/* check number of direct relays */ |
50 |
|
if (directrelay <= 0) |
51 |
|
return; |
84 |
|
} |
85 |
|
|
86 |
|
|
87 |
< |
extern void |
87 |
> |
void |
88 |
|
addvirtuals( /* add virtuals associated with source */ |
89 |
|
int sn, |
90 |
|
int nr |
91 |
|
) |
92 |
|
{ |
93 |
< |
register int i; |
93 |
> |
int i; |
94 |
|
/* check relay limit first */ |
95 |
|
if (nr <= 0) |
96 |
|
return; |
103 |
|
} |
104 |
|
|
105 |
|
|
106 |
< |
extern void |
106 |
> |
void |
107 |
|
vproject( /* create projected source(s) if they exist */ |
108 |
|
OBJREC *o, |
109 |
|
int sn, |
110 |
|
int n |
111 |
|
) |
112 |
|
{ |
113 |
< |
register int i; |
114 |
< |
register VSMATERIAL *vsmat; |
113 |
> |
int i; |
114 |
> |
VSMATERIAL *vsmat; |
115 |
|
MAT4 proj; |
116 |
|
int ns; |
117 |
|
|
132 |
|
} |
133 |
|
|
134 |
|
|
135 |
< |
extern OBJREC * |
135 |
> |
OBJREC * |
136 |
|
vsmaterial( /* get virtual source material pointer */ |
137 |
|
OBJREC *o |
138 |
|
) |
139 |
|
{ |
140 |
< |
register int i; |
141 |
< |
register OBJREC *m; |
140 |
> |
int i; |
141 |
> |
OBJREC *m; |
142 |
|
|
143 |
|
i = o->omod; |
144 |
|
m = findmaterial(objptr(i)); |
152 |
|
} |
153 |
|
|
154 |
|
|
155 |
< |
extern int |
155 |
> |
int |
156 |
|
makevsrc( /* make virtual source if reasonable */ |
157 |
|
OBJREC *op, |
158 |
< |
register int sn, |
158 |
> |
int sn, |
159 |
|
MAT4 pm |
160 |
|
) |
161 |
|
{ |
163 |
|
double maxrad2, d; |
164 |
|
int nsflags; |
165 |
|
SPOT theirspot, ourspot; |
166 |
< |
register int i; |
167 |
< |
|
166 |
> |
int i; |
167 |
> |
/* check for no-op */ |
168 |
> |
if (isident4(pm)) |
169 |
> |
return(0); |
170 |
|
nsflags = source[sn].sflags | (SVIRTUAL|SSPOT|SFOLLOW); |
171 |
|
/* get object center and max. radius */ |
172 |
|
maxrad2 = getdisk(ocent, op, sn); |
280 |
|
} |
281 |
|
|
282 |
|
|
283 |
< |
extern double |
283 |
> |
double |
284 |
|
getdisk( /* get visible object disk */ |
285 |
|
FVECT oc, |
286 |
|
OBJREC *op, |
287 |
< |
register int sn |
287 |
> |
int sn |
288 |
|
) |
289 |
|
{ |
290 |
|
double rad2, roffs, offs, d, rd, rdoto; |
313 |
|
} |
314 |
|
|
315 |
|
|
316 |
< |
extern int |
316 |
> |
int |
317 |
|
vstestvis( /* pretest source visibility */ |
318 |
|
int f, /* virtual source flags */ |
319 |
|
OBJREC *o, /* relay object */ |
320 |
|
FVECT oc, /* relay object center */ |
321 |
|
double or2, /* relay object radius squared */ |
322 |
< |
register int sn /* target source number */ |
322 |
> |
int sn /* target source number */ |
323 |
|
) |
324 |
|
{ |
325 |
|
RAY sr; |
326 |
|
FVECT onorm; |
327 |
< |
FVECT offsdir; |
327 |
> |
double offsdir[3]; |
328 |
|
SRCINDEX si; |
329 |
< |
double or, d; |
329 |
> |
double or, d, d1; |
330 |
|
int stestlim, ssn; |
331 |
|
int nhit, nok; |
332 |
< |
register int i, n; |
332 |
> |
int i, n; |
333 |
|
/* return if pretesting disabled */ |
334 |
|
if (vspretest <= 0) |
335 |
|
return(f); |
340 |
|
/* 32. == heuristic constant */ |
341 |
|
n = 32.*or2/(thescene.cusize*thescene.cusize)*vspretest + .5; |
342 |
|
} else { |
343 |
< |
for (i = 0; i < 3; i++) |
327 |
< |
offsdir[i] = source[sn].sloc[i] - oc[i]; |
343 |
> |
VSUB(offsdir, source[sn].sloc, oc); |
344 |
|
d = DOT(offsdir,offsdir); |
345 |
|
if (d <= FTINY) |
346 |
|
n = 2.*PI * vspretest + .5; |
376 |
|
sr.rorg[i] = oc[i] + offsdir[i] + d*onorm[i]; |
377 |
|
sr.rdir[i] = -onorm[i]; |
378 |
|
} |
379 |
< |
sr.rmax = 0.0; |
364 |
< |
rayorigin(&sr, NULL, PRIMARY, 1.0); |
379 |
> |
rayorigin(&sr, PRIMARY, NULL, NULL); |
380 |
|
} while (!(*ofun[o->otype].funp)(o, &sr)); |
381 |
|
/* check against source */ |
382 |
|
VCOPY(sr.rorg, sr.rop); /* starting from intersection */ |
388 |
|
if (!srcray(&sr, NULL, &si) || sr.rsrc != sn) |
389 |
|
continue; /* can't get there from here */ |
390 |
|
} |
391 |
< |
srcvalue(&sr); /* check sample validity */ |
392 |
< |
if (bright(sr.rcol) <= FTINY) |
391 |
> |
sr.revf = srcvalue; |
392 |
> |
rayvalue(&sr); /* check sample validity */ |
393 |
> |
if ((d = bright(sr.rcol)) <= FTINY) |
394 |
|
continue; |
395 |
|
nok++; /* got sample; check obstructions */ |
396 |
|
rayclear(&sr); |
397 |
+ |
sr.revf = raytrace; |
398 |
|
rayvalue(&sr); |
399 |
< |
if (bright(sr.rcol) > FTINY) |
399 |
> |
if ((d1 = bright(sr.rcol)) > FTINY) { |
400 |
> |
if (d - d1 > FTINY) { |
401 |
> |
#ifdef DEBUG |
402 |
> |
fprintf(stderr, "\tpartially shadowed\n"); |
403 |
> |
#endif |
404 |
> |
return(f); /* intervening transmitter */ |
405 |
> |
} |
406 |
|
nhit++; |
407 |
+ |
} |
408 |
|
if (nhit > 0 && nhit < nok) { |
409 |
|
#ifdef DEBUG |
410 |
|
fprintf(stderr, "\tpartially occluded\n"); |
426 |
|
|
427 |
|
|
428 |
|
#ifdef DEBUG |
429 |
< |
extern void |
429 |
> |
void |
430 |
|
virtverb( /* print verbose description of virtual source */ |
431 |
< |
register int sn, |
431 |
> |
int sn, |
432 |
|
FILE *fp |
433 |
|
) |
434 |
|
{ |
411 |
– |
register int i; |
412 |
– |
|
435 |
|
fprintf(fp, "%s virtual source %d in %s %s\n", |
436 |
|
source[sn].sflags & SDISTANT ? "distant" : "local", |
437 |
|
sn, ofun[source[sn].so->otype].funame, |