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