| 1 |
– |
/* Copyright (c) 1995 Regents of the University of California */ |
| 2 |
– |
|
| 1 |
|
#ifndef lint |
| 2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
| 2 |
> |
static const char RCSid[] = "$Id$"; |
| 3 |
|
#endif |
| 6 |
– |
|
| 4 |
|
/* |
| 5 |
|
* Routines for simulating virtual light sources |
| 6 |
|
* Thus far, we only support planar mirrors. |
| 7 |
+ |
* |
| 8 |
+ |
* External symbols declared in source.h |
| 9 |
|
*/ |
| 10 |
|
|
| 11 |
+ |
#include "copyright.h" |
| 12 |
+ |
|
| 13 |
|
#include "ray.h" |
| 14 |
|
|
| 14 |
– |
#include "octree.h" |
| 15 |
– |
|
| 15 |
|
#include "otypes.h" |
| 16 |
|
|
| 17 |
|
#include "source.h" |
| 22 |
|
#define STESTMAX 32 /* maximum seeks per sample */ |
| 23 |
|
|
| 24 |
|
|
| 26 |
– |
double getdisk(); |
| 27 |
– |
|
| 25 |
|
static OBJECT *vobject; /* virtual source objects */ |
| 26 |
|
static int nvobjects = 0; /* number of virtual source objects */ |
| 27 |
|
|
| 28 |
|
|
| 29 |
+ |
void |
| 30 |
|
markvirtuals() /* find and mark virtual sources */ |
| 31 |
|
{ |
| 32 |
|
register OBJREC *o; |
| 35 |
|
if (directrelay <= 0) |
| 36 |
|
return; |
| 37 |
|
/* find virtual source objects */ |
| 38 |
< |
for (i = 0; i < nobjects; i++) { |
| 38 |
> |
for (i = 0; i < nsceneobjs; i++) { |
| 39 |
|
o = objptr(i); |
| 40 |
|
if (!issurface(o->otype) || o->omod == OVOID) |
| 41 |
|
continue; |
| 49 |
|
if (nvobjects == 0) |
| 50 |
|
vobject = (OBJECT *)malloc(sizeof(OBJECT)); |
| 51 |
|
else |
| 52 |
< |
vobject = (OBJECT *)realloc((char *)vobject, |
| 52 |
> |
vobject = (OBJECT *)realloc((void *)vobject, |
| 53 |
|
(unsigned)(nvobjects+1)*sizeof(OBJECT)); |
| 54 |
|
if (vobject == NULL) |
| 55 |
|
error(SYSTEM, "out of memory in addvirtuals"); |
| 64 |
|
for (i = nsources; i-- > 0; ) |
| 65 |
|
addvirtuals(i, directrelay); |
| 66 |
|
/* done with our object list */ |
| 67 |
< |
free((char *)vobject); |
| 67 |
> |
free((void *)vobject); |
| 68 |
|
nvobjects = 0; |
| 69 |
|
} |
| 70 |
|
|
| 71 |
|
|
| 72 |
+ |
void |
| 73 |
|
addvirtuals(sn, nr) /* add virtuals associated with source */ |
| 74 |
|
int sn; |
| 75 |
|
int nr; |
| 87 |
|
} |
| 88 |
|
|
| 89 |
|
|
| 90 |
+ |
void |
| 91 |
|
vproject(o, sn, n) /* create projected source(s) if they exist */ |
| 92 |
|
OBJREC *o; |
| 93 |
|
int sn; |
| 123 |
|
register OBJREC *m; |
| 124 |
|
|
| 125 |
|
i = o->omod; |
| 126 |
< |
m = objptr(i); |
| 126 |
> |
m = findmaterial(objptr(i)); |
| 127 |
> |
if (m == NULL) |
| 128 |
> |
return(objptr(i)); |
| 129 |
|
if (m->otype != MAT_ILLUM || m->oargs.nsargs < 1 || |
| 130 |
|
!strcmp(m->oargs.sarg[0], VOIDID) || |
| 131 |
< |
(i = modifier(m->oargs.sarg[0])) == OVOID) |
| 131 |
> |
(i = lastmod(objndx(m), m->oargs.sarg[0])) == OVOID) |
| 132 |
|
return(m); /* direct modifier */ |
| 133 |
|
return(objptr(i)); /* illum alternate */ |
| 134 |
|
} |
| 196 |
|
else |
| 197 |
|
nsflags &= ~SSPOT; |
| 198 |
|
if (source[sn].sflags & SSPOT) { |
| 199 |
< |
copystruct(&theirspot, source[sn].sl.s); |
| 199 |
> |
theirspot = *(source[sn].sl.s); |
| 200 |
|
multv3(theirspot.aim, source[sn].sl.s->aim, pm); |
| 201 |
|
normalize(theirspot.aim); |
| 202 |
|
if (nsflags & SSPOT) { |
| 206 |
|
return(-1); /* no overlap */ |
| 207 |
|
} else { |
| 208 |
|
nsflags |= SSPOT; |
| 209 |
< |
copystruct(&ourspot, &theirspot); |
| 209 |
> |
ourspot = theirspot; |
| 210 |
|
d = 2.*ourspot.siz; |
| 211 |
|
} |
| 212 |
|
if (ourspot.siz < d-FTINY) { /* it shrunk */ |
| 246 |
|
if (nsflags & SSPOT) { |
| 247 |
|
if ((source[i].sl.s = (SPOT *)malloc(sizeof(SPOT))) == NULL) |
| 248 |
|
goto memerr; |
| 249 |
< |
copystruct(source[i].sl.s, &ourspot); |
| 249 |
> |
*(source[i].sl.s) = ourspot; |
| 250 |
|
} |
| 251 |
|
if (nsflags & SPROX) |
| 252 |
|
source[i].sl.prox = source[sn].sl.prox; |
| 397 |
|
|
| 398 |
|
|
| 399 |
|
#ifdef DEBUG |
| 400 |
+ |
void |
| 401 |
|
virtverb(sn, fp) /* print verbose description of virtual source */ |
| 402 |
|
register int sn; |
| 403 |
|
FILE *fp; |