ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/srcsupp.c
(Generate patch)

Comparing ray/src/rt/srcsupp.c (file contents):
Revision 1.1 by greg, Thu Jun 20 13:44:36 1991 UTC vs.
Revision 1.4 by greg, Fri Jun 21 16:44:01 1991 UTC

# Line 44 | Line 44 | initstypes()                   /* initialize source dispatch table */
44   }
45  
46  
47 < SRCREC *
47 > int
48   newsource()                     /* allocate new source in our array */
49   {
50          if (nsources == 0)
# Line 53 | Line 53 | newsource()                    /* allocate new source in our array */
53                  source = (SRCREC *)realloc((char *)source,
54                                  (unsigned)(nsources+1)*sizeof(SRCREC));
55          if (source == NULL)
56 <                return(NULL);
56 >                return(-1);
57          source[nsources].sflags = 0;
58          source[nsources].nhits = 1;
59          source[nsources].ntests = 2;    /* initial hit probability = 1/2 */
60 <        return(&source[nsources++]);
60 >        return(nsources++);
61   }
62  
63  
# Line 150 | Line 150 | SPOT *
150   makespot(m)                     /* make a spotlight */
151   register OBJREC  *m;
152   {
153        extern double  cos();
153          register SPOT  *ns;
154  
155          if ((ns = (SPOT *)malloc(sizeof(SPOT))) == NULL)
# Line 180 | Line 179 | OBJREC  *op;
179                          ocent[i] += VERTEX(f,j)[i];
180                  ocent[i] /= (double)f->nv;
181          }
182 +        if (f->area == 0.)
183 +                return(0.);
184          maxrad2 = 0.;
185          for (j = 0; j < f->nv; j++) {
186                  d2 = dist2(VERTEX(f,j), ocent);
# Line 226 | Line 227 | OBJREC  *op;
227          co = getcone(op, 0);
228          VCOPY(nvec, co->ad);
229          return(DOT(nvec, CO_P0(co)));
230 + }
231 +
232 +
233 + commonspot(sp1, sp2, org)       /* set sp1 to intersection of sp1 and sp2 */
234 + register SPOT  *sp1, *sp2;
235 + FVECT  org;
236 + {
237 +        FVECT  cent;
238 +        double  rad2, cos1, cos2;
239 +
240 +        cos1 = 1. - sp1->siz/(2.*PI);
241 +        cos2 = 1. - sp2->siz/(2.*PI);
242 +        if (sp2->siz >= 2.*PI-FTINY)            /* BIG, just check overlap */
243 +                return(DOT(sp1->aim,sp2->aim) >= cos1*cos2 -
244 +                                        sqrt((1.-cos1*cos1)*(1.-cos2*cos2)));
245 +                                /* compute and check disks */
246 +        rad2 = intercircle(cent, sp1->aim, sp2->aim,
247 +                        1./(cos1*cos1) - 1.,  1./(cos2*cos2) - 1.);
248 +        if (rad2 <= FTINY || normalize(cent) == 0.)
249 +                return(0);
250 +        VCOPY(sp1->aim, cent);
251 +        sp1->siz = 2.*PI*(1. - 1./sqrt(1.+rad2));
252 +        return(1);
253 + }
254 +
255 +
256 + commonbeam(sp1, sp2, dir)       /* set sp1 to intersection of sp1 and sp2 */
257 + register SPOT  *sp1, *sp2;
258 + FVECT  dir;
259 + {
260 +        FVECT  cent, c1, c2;
261 +        double  rad2, d;
262 +        register int  i;
263 +                                        /* move centers to common plane */
264 +        d = DOT(sp1->aim, dir);
265 +        for (i = 0; i < 3; i++)
266 +                c1[i] = sp1->aim[i] - d*dir[i];
267 +        d = DOT(sp2->aim, dir);
268 +        for (i = 0; i < 3; i++)
269 +                c2[i] = sp2->aim[i] - d*dir[i];
270 +                                        /* compute overlap */
271 +        rad2 = intercircle(cent, c1, c2, sp1->siz/PI, sp2->siz/PI);
272 +        if (rad2 <= FTINY)
273 +                return(0);
274 +        VCOPY(sp1->aim, cent);
275 +        sp1->siz = PI*rad2;
276 +        return(1);
277 + }
278 +
279 +
280 + checkspot(sp, nrm)              /* check spotlight for behind source */
281 + register SPOT  *sp;     /* spotlight */
282 + FVECT  nrm;             /* source surface normal */
283 + {
284 +        double  d, d1;
285 +
286 +        d = DOT(sp->aim, nrm);
287 +        if (d > FTINY)                  /* center in front? */
288 +                return(0);
289 +                                        /* else check horizon */
290 +        d1 = 1. - sp->siz/(2.*PI);
291 +        return(1.-FTINY-d*d > d1*d1);
292 + }
293 +
294 +
295 + double
296 + intercircle(cc, c1, c2, r1s, r2s)       /* intersect two circles */
297 + FVECT  cc;                      /* midpoint (return value) */
298 + FVECT  c1, c2;                  /* circle centers */
299 + double  r1s, r2s;               /* radii squared */
300 + {
301 +        double  a2, d2, l;
302 +        FVECT  disp;
303 +        register int  i;
304 +
305 +        for (i = 0; i < 3; i++)
306 +                disp[i] = c2[i] - c1[i];
307 +        d2 = DOT(disp,disp);
308 +                                        /* circle within overlap? */
309 +        if (r1s < r2s) {
310 +                if (r2s >= r1s + d2) {
311 +                        VCOPY(cc, c1);
312 +                        return(r1s);
313 +                }
314 +        } else {
315 +                if (r1s >= r2s + d2) {
316 +                        VCOPY(cc, c2);
317 +                        return(r2s);
318 +                }
319 +        }
320 +        a2 = .25*(2.*(r1s+r2s) - d2 - (r2s-r1s)*(r2s-r1s)/d2);
321 +                                        /* no overlap? */
322 +        if (a2 <= 0.)
323 +                return(0.);
324 +                                        /* overlap, compute center */
325 +        l = sqrt((r1s - a2)/d2);
326 +        for (i = 0; i < 3; i++)
327 +                cc[i] = c1[i] + l*disp[i];
328 +        return(a2);
329   }
330  
331  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines