--- ray/src/rt/srcsupp.c 1992/08/28 15:10:47 2.6 +++ ray/src/rt/srcsupp.c 2007/02/26 21:16:02 2.16 @@ -1,13 +1,14 @@ -/* Copyright (c) 1992 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: srcsupp.c,v 2.16 2007/02/26 21:16:02 greg Exp $"; #endif - /* * Support routines for source objects and materials + * + * External symbols declared in source.h */ +#include "copyright.h" + #include "ray.h" #include "otypes.h" @@ -18,7 +19,7 @@ static char SCCSid[] = "$SunId$ LBL"; #include "face.h" -#define SRCINC 4 /* realloc increment for array */ +#define SRCINC 8 /* realloc increment for array */ SRCREC *source = NULL; /* our list of sources */ int nsources = 0; /* the number of sources */ @@ -26,13 +27,10 @@ int nsources = 0; /* the number of sources */ SRCFUNC sfun[NUMOTYPE]; /* source dispatch table */ +void initstypes() /* initialize source dispatch table */ { extern VSMATERIAL mirror_vs, direct1_vs, direct2_vs; - extern int fsetsrc(), ssetsrc(), sphsetsrc(), cylsetsrc(), rsetsrc(); - extern int nopart(), flatpart(), cylpart(); - extern double fgetplaneq(), rgetplaneq(); - extern double fgetmaxdisk(), rgetmaxdisk(); static SOBJECT fsobj = {fsetsrc, flatpart, fgetplaneq, fgetmaxdisk}; static SOBJECT ssobj = {ssetsrc, nopart}; static SOBJECT sphsobj = {sphsetsrc, nopart}; @@ -56,17 +54,21 @@ newsource() /* allocate new source in our array */ if (nsources == 0) source = (SRCREC *)malloc(SRCINC*sizeof(SRCREC)); else if (nsources%SRCINC == 0) - source = (SRCREC *)realloc((char *)source, + source = (SRCREC *)realloc((void *)source, (unsigned)(nsources+SRCINC)*sizeof(SRCREC)); if (source == NULL) return(-1); source[nsources].sflags = 0; source[nsources].nhits = 1; - source[nsources].ntests = 2; /* initial hit probability = 1/2 */ + source[nsources].ntests = 2; /* initial hit probability = 50% */ +#if SHADCACHE + source[nsources].obscache = NULL; +#endif return(nsources++); } +void setflatss(src) /* set sampling for a flat source */ register SRCREC *src; { @@ -86,6 +88,7 @@ register SRCREC *src; } +void fsetsrc(src, so) /* set a face as a source */ register SRCREC *src; OBJREC *so; @@ -98,6 +101,8 @@ OBJREC *so; src->so = so; /* get the face */ f = getface(so); + if (f->area == 0.0) + objerror(so, USER, "zero source area"); /* find the center */ for (j = 0; j < 3; j++) { src->sloc[j] = 0.0; @@ -106,7 +111,7 @@ OBJREC *so; src->sloc[j] /= (double)f->nv; } if (!inface(src->sloc, f)) - objerror(so, USER, "cannot hit center"); + objerror(so, USER, "cannot hit source center"); src->sflags |= SFLAT; VCOPY(src->snorm, f->norm); src->ss2 = f->area; @@ -119,8 +124,7 @@ OBJREC *so; } src->srad = sqrt(src->srad); /* compute size vectors */ - if (f->nv == 4 || (f->nv == 5 && /* parallelogram case */ - dist2(VERTEX(f,0),VERTEX(f,4)) <= FTINY*FTINY)) + if (f->nv == 4) /* parallelogram case */ for (j = 0; j < 3; j++) { src->ss[SU][j] = .5*(VERTEX(f,1)[j]-VERTEX(f,0)[j]); src->ss[SV][j] = .5*(VERTEX(f,3)[j]-VERTEX(f,0)[j]); @@ -130,6 +134,7 @@ OBJREC *so; } +void ssetsrc(src, so) /* set a source as a source */ register SRCREC *src; register OBJREC *so; @@ -156,6 +161,7 @@ register OBJREC *so; } +void sphsetsrc(src, so) /* set a sphere as a source */ register SRCREC *src; register OBJREC *so; @@ -167,7 +173,7 @@ register OBJREC *so; if (so->oargs.nfargs != 4) objerror(so, USER, "bad # arguments"); if (so->oargs.farg[3] <= FTINY) - objerror(so, USER, "illegal radius"); + objerror(so, USER, "illegal source radius"); VCOPY(src->sloc, so->oargs.farg); src->srad = so->oargs.farg[3]; src->ss2 = PI * src->srad * src->srad; @@ -178,6 +184,7 @@ register OBJREC *so; } +void rsetsrc(src, so) /* set a ring (disk) as a source */ register SRCREC *src; OBJREC *so; @@ -188,9 +195,11 @@ OBJREC *so; src->so = so; /* get the ring */ co = getcone(so, 0); + if (CO_R1(co) <= FTINY) + objerror(so, USER, "illegal source radius"); VCOPY(src->sloc, CO_P0(co)); if (CO_R0(co) > 0.0) - objerror(so, USER, "cannot hit center"); + objerror(so, USER, "cannot hit source center"); src->sflags |= SFLAT; VCOPY(src->snorm, co->ad); src->srad = CO_R1(co); @@ -199,6 +208,7 @@ OBJREC *so; } +void cylsetsrc(src, so) /* set a cylinder as a source */ register SRCREC *src; OBJREC *so; @@ -210,6 +220,8 @@ OBJREC *so; src->so = so; /* get the cylinder */ co = getcone(so, 0); + if (CO_R0(co) <= FTINY) + objerror(so, USER, "illegal source radius"); if (CO_R0(co) > .2*co->al) /* heuristic constraint */ objerror(so, WARNING, "source aspect too small"); src->sflags |= SCYL; @@ -243,6 +255,8 @@ register OBJREC *m; return(ns); if ((ns = (SPOT *)malloc(sizeof(SPOT))) == NULL) return(NULL); + if (m->oargs.farg[3] <= FTINY) + objerror(m, USER, "zero angle"); ns->siz = 2.0*PI * (1.0 - cos(PI/180.0/2.0 * m->oargs.farg[3])); VCOPY(ns->aim, m->oargs.farg+4); if ((ns->flen = normalize(ns->aim)) == 0.0) @@ -252,17 +266,17 @@ register OBJREC *m; } -spotout(r, s, dist) /* check if we're outside spot region */ +int +spotout(r, s) /* check if we're outside spot region */ register RAY *r; register SPOT *s; -int dist; { double d; FVECT vd; if (s == NULL) return(0); - if (dist) { /* distant source */ + if (s->flen < -FTINY) { /* distant source */ vd[0] = s->aim[0] - r->rorg[0]; vd[1] = s->aim[1] - r->rorg[1]; vd[2] = s->aim[2] - r->rorg[2]; @@ -353,6 +367,7 @@ OBJREC *op; } +int commonspot(sp1, sp2, org) /* set sp1 to intersection of sp1 and sp2 */ register SPOT *sp1, *sp2; FVECT org; @@ -376,6 +391,7 @@ FVECT org; } +int commonbeam(sp1, sp2, dir) /* set sp1 to intersection of sp1 and sp2 */ register SPOT *sp1, *sp2; FVECT dir; @@ -400,6 +416,7 @@ FVECT dir; } +int checkspot(sp, nrm) /* check spotlight for behind source */ register SPOT *sp; /* spotlight */ FVECT nrm; /* source surface normal */