--- ray/src/rt/virtuals.c 1995/08/26 14:07:46 2.4 +++ ray/src/rt/virtuals.c 2004/03/02 01:13:45 2.13 @@ -1,18 +1,17 @@ -/* Copyright (c) 1995 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: virtuals.c,v 2.13 2004/03/02 01:13:45 greg Exp $"; #endif - /* * Routines for simulating virtual light sources * Thus far, we only support planar mirrors. + * + * External symbols declared in source.h */ +#include "copyright.h" + #include "ray.h" -#include "octree.h" - #include "otypes.h" #include "source.h" @@ -23,12 +22,11 @@ static char SCCSid[] = "$SunId$ LBL"; #define STESTMAX 32 /* maximum seeks per sample */ -double getdisk(); - static OBJECT *vobject; /* virtual source objects */ static int nvobjects = 0; /* number of virtual source objects */ +void markvirtuals() /* find and mark virtual sources */ { register OBJREC *o; @@ -37,7 +35,7 @@ markvirtuals() /* find and mark virtual sources */ if (directrelay <= 0) return; /* find virtual source objects */ - for (i = 0; i < nobjects; i++) { + for (i = 0; i < nsceneobjs; i++) { o = objptr(i); if (!issurface(o->otype) || o->omod == OVOID) continue; @@ -51,7 +49,7 @@ markvirtuals() /* find and mark virtual sources */ if (nvobjects == 0) vobject = (OBJECT *)malloc(sizeof(OBJECT)); else - vobject = (OBJECT *)realloc((char *)vobject, + vobject = (OBJECT *)realloc((void *)vobject, (unsigned)(nvobjects+1)*sizeof(OBJECT)); if (vobject == NULL) error(SYSTEM, "out of memory in addvirtuals"); @@ -66,11 +64,12 @@ markvirtuals() /* find and mark virtual sources */ for (i = nsources; i-- > 0; ) addvirtuals(i, directrelay); /* done with our object list */ - free((char *)vobject); + free((void *)vobject); nvobjects = 0; } +void addvirtuals(sn, nr) /* add virtuals associated with source */ int sn; int nr; @@ -88,6 +87,7 @@ int nr; } +void vproject(o, sn, n) /* create projected source(s) if they exist */ OBJREC *o; int sn; @@ -123,10 +123,12 @@ OBJREC *o; register OBJREC *m; i = o->omod; - m = objptr(i); + m = findmaterial(objptr(i)); + if (m == NULL) + return(objptr(i)); if (m->otype != MAT_ILLUM || m->oargs.nsargs < 1 || !strcmp(m->oargs.sarg[0], VOIDID) || - (i = modifier(m->oargs.sarg[0])) == OVOID) + (i = lastmod(objndx(m), m->oargs.sarg[0])) == OVOID) return(m); /* direct modifier */ return(objptr(i)); /* illum alternate */ } @@ -157,7 +159,7 @@ MAT4 pm; normalize(nsloc); VCOPY(ourspot.aim, ocent); ourspot.siz = PI*maxrad2; - ourspot.flen = 0.; + ourspot.flen = -1.; if (source[sn].sflags & SSPOT) { multp3(theirspot.aim, source[sn].sl.s->aim, pm); /* adjust for source size */ @@ -194,7 +196,7 @@ MAT4 pm; else nsflags &= ~SSPOT; if (source[sn].sflags & SSPOT) { - copystruct(&theirspot, source[sn].sl.s); + theirspot = *(source[sn].sl.s); multv3(theirspot.aim, source[sn].sl.s->aim, pm); normalize(theirspot.aim); if (nsflags & SSPOT) { @@ -204,7 +206,7 @@ MAT4 pm; return(-1); /* no overlap */ } else { nsflags |= SSPOT; - copystruct(&ourspot, &theirspot); + ourspot = theirspot; d = 2.*ourspot.siz; } if (ourspot.siz < d-FTINY) { /* it shrunk */ @@ -244,7 +246,7 @@ MAT4 pm; if (nsflags & SSPOT) { if ((source[i].sl.s = (SPOT *)malloc(sizeof(SPOT))) == NULL) goto memerr; - copystruct(source[i].sl.s, &ourspot); + *(source[i].sl.s) = ourspot; } if (nsflags & SPROX) source[i].sl.prox = source[sn].sl.prox; @@ -395,6 +397,7 @@ register int sn; /* target source number */ #ifdef DEBUG +void virtverb(sn, fp) /* print verbose description of virtual source */ register int sn; FILE *fp;