--- ray/src/rt/srcsupp.c 1995/08/24 20:56:08 2.7 +++ ray/src/rt/srcsupp.c 2003/12/31 02:03:08 2.13 @@ -1,13 +1,14 @@ -/* Copyright (c) 1995 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: srcsupp.c,v 2.13 2003/12/31 02:03:08 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].nhits = 0; + source[nsources].ntests = 1; /* initial hit probability = 0 */ +#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; @@ -129,6 +132,7 @@ OBJREC *so; } +void ssetsrc(src, so) /* set a source as a source */ register SRCREC *src; register OBJREC *so; @@ -155,6 +159,7 @@ register OBJREC *so; } +void sphsetsrc(src, so) /* set a sphere as a source */ register SRCREC *src; register OBJREC *so; @@ -177,6 +182,7 @@ register OBJREC *so; } +void rsetsrc(src, so) /* set a ring (disk) as a source */ register SRCREC *src; OBJREC *so; @@ -198,6 +204,7 @@ OBJREC *so; } +void cylsetsrc(src, so) /* set a cylinder as a source */ register SRCREC *src; OBJREC *so; @@ -251,17 +258,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]; @@ -352,6 +359,7 @@ OBJREC *op; } +int commonspot(sp1, sp2, org) /* set sp1 to intersection of sp1 and sp2 */ register SPOT *sp1, *sp2; FVECT org; @@ -375,6 +383,7 @@ FVECT org; } +int commonbeam(sp1, sp2, dir) /* set sp1 to intersection of sp1 and sp2 */ register SPOT *sp1, *sp2; FVECT dir; @@ -399,6 +408,7 @@ FVECT dir; } +int checkspot(sp, nrm) /* check spotlight for behind source */ register SPOT *sp; /* spotlight */ FVECT nrm; /* source surface normal */