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.5 by greg, Mon Jun 24 16:00:30 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 169 | Line 168 | FVECT  ocent;
168   OBJREC  *op;
169   {
170          double  maxrad2;
171 <        double  d2;
171 >        double  d;
172          register int  i, j;
173          register FACE  *f;
174          
175          f = getface(op);
176 +        if (f->area == 0.)
177 +                return(0.);
178          for (i = 0; i < 3; i++) {
179                  ocent[i] = 0.;
180                  for (j = 0; j < f->nv; j++)
181                          ocent[i] += VERTEX(f,j)[i];
182                  ocent[i] /= (double)f->nv;
183          }
184 +        d = DOT(ocent,f->norm);
185 +        for (i = 0; i < 3; i++)
186 +                ocent[i] += (f->offset - d)*f->norm[i];
187          maxrad2 = 0.;
188          for (j = 0; j < f->nv; j++) {
189 <                d2 = dist2(VERTEX(f,j), ocent);
190 <                if (d2 > maxrad2)
191 <                        maxrad2 = d2;
189 >                d = dist2(VERTEX(f,j), ocent);
190 >                if (d > maxrad2)
191 >                        maxrad2 = d;
192          }
193          return(maxrad2);
194   }
# Line 226 | Line 230 | OBJREC  *op;
230          co = getcone(op, 0);
231          VCOPY(nvec, co->ad);
232          return(DOT(nvec, CO_P0(co)));
233 + }
234 +
235 +
236 + commonspot(sp1, sp2, org)       /* set sp1 to intersection of sp1 and sp2 */
237 + register SPOT  *sp1, *sp2;
238 + FVECT  org;
239 + {
240 +        FVECT  cent;
241 +        double  rad2, cos1, cos2;
242 +
243 +        cos1 = 1. - sp1->siz/(2.*PI);
244 +        cos2 = 1. - sp2->siz/(2.*PI);
245 +        if (sp2->siz >= 2.*PI-FTINY)            /* BIG, just check overlap */
246 +                return(DOT(sp1->aim,sp2->aim) >= cos1*cos2 -
247 +                                        sqrt((1.-cos1*cos1)*(1.-cos2*cos2)));
248 +                                /* compute and check disks */
249 +        rad2 = intercircle(cent, sp1->aim, sp2->aim,
250 +                        1./(cos1*cos1) - 1.,  1./(cos2*cos2) - 1.);
251 +        if (rad2 <= FTINY || normalize(cent) == 0.)
252 +                return(0);
253 +        VCOPY(sp1->aim, cent);
254 +        sp1->siz = 2.*PI*(1. - 1./sqrt(1.+rad2));
255 +        return(1);
256 + }
257 +
258 +
259 + commonbeam(sp1, sp2, dir)       /* set sp1 to intersection of sp1 and sp2 */
260 + register SPOT  *sp1, *sp2;
261 + FVECT  dir;
262 + {
263 +        FVECT  cent, c1, c2;
264 +        double  rad2, d;
265 +        register int  i;
266 +                                        /* move centers to common plane */
267 +        d = DOT(sp1->aim, dir);
268 +        for (i = 0; i < 3; i++)
269 +                c1[i] = sp1->aim[i] - d*dir[i];
270 +        d = DOT(sp2->aim, dir);
271 +        for (i = 0; i < 3; i++)
272 +                c2[i] = sp2->aim[i] - d*dir[i];
273 +                                        /* compute overlap */
274 +        rad2 = intercircle(cent, c1, c2, sp1->siz/PI, sp2->siz/PI);
275 +        if (rad2 <= FTINY)
276 +                return(0);
277 +        VCOPY(sp1->aim, cent);
278 +        sp1->siz = PI*rad2;
279 +        return(1);
280 + }
281 +
282 +
283 + checkspot(sp, nrm)              /* check spotlight for behind source */
284 + register SPOT  *sp;     /* spotlight */
285 + FVECT  nrm;             /* source surface normal */
286 + {
287 +        double  d, d1;
288 +
289 +        d = DOT(sp->aim, nrm);
290 +        if (d > FTINY)                  /* center in front? */
291 +                return(0);
292 +                                        /* else check horizon */
293 +        d1 = 1. - sp->siz/(2.*PI);
294 +        return(1.-FTINY-d*d > d1*d1);
295 + }
296 +
297 +
298 + double
299 + intercircle(cc, c1, c2, r1s, r2s)       /* intersect two circles */
300 + FVECT  cc;                      /* midpoint (return value) */
301 + FVECT  c1, c2;                  /* circle centers */
302 + double  r1s, r2s;               /* radii squared */
303 + {
304 +        double  a2, d2, l;
305 +        FVECT  disp;
306 +        register int  i;
307 +
308 +        for (i = 0; i < 3; i++)
309 +                disp[i] = c2[i] - c1[i];
310 +        d2 = DOT(disp,disp);
311 +                                        /* circle within overlap? */
312 +        if (r1s < r2s) {
313 +                if (r2s >= r1s + d2) {
314 +                        VCOPY(cc, c1);
315 +                        return(r1s);
316 +                }
317 +        } else {
318 +                if (r1s >= r2s + d2) {
319 +                        VCOPY(cc, c2);
320 +                        return(r2s);
321 +                }
322 +        }
323 +        a2 = .25*(2.*(r1s+r2s) - d2 - (r2s-r1s)*(r2s-r1s)/d2);
324 +                                        /* no overlap? */
325 +        if (a2 <= 0.)
326 +                return(0.);
327 +                                        /* overlap, compute center */
328 +        l = sqrt((r1s - a2)/d2);
329 +        for (i = 0; i < 3; i++)
330 +                cc[i] = c1[i] + l*disp[i];
331 +        return(a2);
332   }
333  
334  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines