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.2 by greg, Thu Jun 20 16:36:46 1991 UTC vs.
Revision 1.7 by greg, Tue Jun 25 15:34:17 1991 UTC

# Line 105 | Line 105 | register OBJREC  *so;
105          theta = PI/180.0/2.0 * so->oargs.farg[3];
106          if (theta <= FTINY)
107                  objerror(so, USER, "zero size");
108 <        src->ss = theta >= PI/4 ? 1.0 : tan(theta);
108 >        src->ss = theta >= PI/4.0 ? 1.0 : tan(theta);
109          src->ss2 = 2.0*PI * (1.0 - cos(theta));
110   }
111  
# 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 + spotdisk(oc, op, sp, pos)       /* intersect spot with object op */
300 + FVECT  oc;
301 + OBJREC  *op;
302 + register SPOT  *sp;
303 + FVECT  pos;
304 + {
305 +        FVECT  onorm;
306 +        double  offs, d, dist;
307 +        register int  i;
308 +
309 +        offs = getplaneq(onorm, op);
310 +        d = -DOT(onorm, sp->aim);
311 +        if (d >= -FTINY && d <= FTINY)
312 +                return(0.);
313 +        dist = (DOT(pos, onorm) - offs)/d;
314 +        if (dist < 0.)
315 +                return(0.);
316 +        for (i = 0; i < 3; i++)
317 +                oc[i] = pos[i] + dist*sp->aim[i];
318 +        return(sp->siz*dist*dist/PI/(d*d));
319 + }
320 +
321 +
322 + double
323 + beamdisk(oc, op, sp, dir)       /* intersect beam with object op */
324 + FVECT  oc;
325 + OBJREC  *op;
326 + register SPOT  *sp;
327 + FVECT  dir;
328 + {
329 +        FVECT  onorm;
330 +        double  offs, d, dist;
331 +        register int  i;
332 +
333 +        offs = getplaneq(onorm, op);
334 +        d = -DOT(onorm, dir);
335 +        if (d >= -FTINY && d <= FTINY)
336 +                return(0.);
337 +        dist = (DOT(sp->aim, onorm) - offs)/d;
338 +        for (i = 0; i < 3; i++)
339 +                oc[i] = sp->aim[i] + dist*dir[i];
340 +        return(sp->siz/PI/(d*d));
341 + }
342 +
343 +
344 + double
345 + intercircle(cc, c1, c2, r1s, r2s)       /* intersect two circles */
346 + FVECT  cc;                      /* midpoint (return value) */
347 + FVECT  c1, c2;                  /* circle centers */
348 + double  r1s, r2s;               /* radii squared */
349 + {
350 +        double  a2, d2, l;
351 +        FVECT  disp;
352 +        register int  i;
353 +
354 +        for (i = 0; i < 3; i++)
355 +                disp[i] = c2[i] - c1[i];
356 +        d2 = DOT(disp,disp);
357 +                                        /* circle within overlap? */
358 +        if (r1s < r2s) {
359 +                if (r2s >= r1s + d2) {
360 +                        VCOPY(cc, c1);
361 +                        return(r1s);
362 +                }
363 +        } else {
364 +                if (r1s >= r2s + d2) {
365 +                        VCOPY(cc, c2);
366 +                        return(r2s);
367 +                }
368 +        }
369 +        a2 = .25*(2.*(r1s+r2s) - d2 - (r2s-r1s)*(r2s-r1s)/d2);
370 +                                        /* no overlap? */
371 +        if (a2 <= 0.)
372 +                return(0.);
373 +                                        /* overlap, compute center */
374 +        l = sqrt((r1s - a2)/d2);
375 +        for (i = 0; i < 3; i++)
376 +                cc[i] = c1[i] + l*disp[i];
377 +        return(a2);
378   }
379  
380  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines