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.4 by greg, Fri Jun 21 16:44:01 1991 UTC vs.
Revision 1.13 by greg, Fri Sep 13 13:44:10 1991 UTC

# Line 27 | Line 27 | SRCFUNC  sfun[NUMOTYPE];               /* source dispatch table */
27  
28   initstypes()                    /* initialize source dispatch table */
29   {
30 <        extern VSMATERIAL  mirror_vs;
30 >        extern VSMATERIAL  mirror_vs, direct1_vs, direct2_vs;
31          extern int  fsetsrc(), ssetsrc(), sphsetsrc(), rsetsrc();
32          extern double  fgetplaneq(), rgetplaneq();
33          extern double  fgetmaxdisk(), rgetmaxdisk();
# Line 37 | Line 37 | initstypes()                   /* initialize source dispatch table */
37          static SOBJECT  rsobj = {rsetsrc, rgetplaneq, rgetmaxdisk};
38  
39          sfun[MAT_MIRROR].mf = &mirror_vs;
40 +        sfun[MAT_DIRECT1].mf = &direct1_vs;
41 +        sfun[MAT_DIRECT2].mf = &direct2_vs;
42          sfun[OBJ_FACE].of = &fsobj;
43          sfun[OBJ_SOURCE].of = &ssobj;
44          sfun[OBJ_SPHERE].of = &sphsobj;
# Line 47 | Line 49 | initstypes()                   /* initialize source dispatch table */
49   int
50   newsource()                     /* allocate new source in our array */
51   {
52 + #define SRCINC  4
53          if (nsources == 0)
54 <                source = (SRCREC *)malloc(sizeof(SRCREC));
55 <        else
54 >                source = (SRCREC *)malloc(SRCINC*sizeof(SRCREC));
55 >        else if (nsources%SRCINC == 0)
56                  source = (SRCREC *)realloc((char *)source,
57 <                                (unsigned)(nsources+1)*sizeof(SRCREC));
57 >                                (unsigned)(nsources+SRCINC)*sizeof(SRCREC));
58          if (source == NULL)
59                  return(-1);
60          source[nsources].sflags = 0;
61          source[nsources].nhits = 1;
62          source[nsources].ntests = 2;    /* initial hit probability = 1/2 */
63          return(nsources++);
64 + #undef SRCINC
65   }
66  
67  
# Line 105 | Line 109 | register OBJREC  *so;
109          theta = PI/180.0/2.0 * so->oargs.farg[3];
110          if (theta <= FTINY)
111                  objerror(so, USER, "zero size");
112 <        src->ss = theta >= PI/4 ? 1.0 : tan(theta);
112 >        src->ss = theta >= PI/4.0 ? 1.0 : tan(theta);
113          src->ss2 = 2.0*PI * (1.0 - cos(theta));
114   }
115  
# Line 168 | Line 172 | FVECT  ocent;
172   OBJREC  *op;
173   {
174          double  maxrad2;
175 <        double  d2;
175 >        double  d;
176          register int  i, j;
177          register FACE  *f;
178          
179          f = getface(op);
180 +        if (f->area == 0.)
181 +                return(0.);
182          for (i = 0; i < 3; i++) {
183                  ocent[i] = 0.;
184                  for (j = 0; j < f->nv; j++)
185                          ocent[i] += VERTEX(f,j)[i];
186                  ocent[i] /= (double)f->nv;
187          }
188 <        if (f->area == 0.)
189 <                return(0.);
188 >        d = DOT(ocent,f->norm);
189 >        for (i = 0; i < 3; i++)
190 >                ocent[i] += (f->offset - d)*f->norm[i];
191          maxrad2 = 0.;
192          for (j = 0; j < f->nv; j++) {
193 <                d2 = dist2(VERTEX(f,j), ocent);
194 <                if (d2 > maxrad2)
195 <                        maxrad2 = d2;
193 >                d = dist2(VERTEX(f,j), ocent);
194 >                if (d > maxrad2)
195 >                        maxrad2 = d;
196          }
197          return(maxrad2);
198   }
# Line 285 | Line 292 | FVECT  nrm;            /* source surface normal */
292  
293          d = DOT(sp->aim, nrm);
294          if (d > FTINY)                  /* center in front? */
295 <                return(0);
295 >                return(1);
296                                          /* else check horizon */
297          d1 = 1. - sp->siz/(2.*PI);
298 <        return(1.-FTINY-d*d > d1*d1);
298 >        return(1.-FTINY-d*d < d1*d1);
299   }
300  
301  
302   double
303 + spotdisk(oc, op, sp, pos)       /* intersect spot with object op */
304 + FVECT  oc;
305 + OBJREC  *op;
306 + register SPOT  *sp;
307 + FVECT  pos;
308 + {
309 +        FVECT  onorm;
310 +        double  offs, d, dist;
311 +        register int  i;
312 +
313 +        offs = getplaneq(onorm, op);
314 +        d = -DOT(onorm, sp->aim);
315 +        if (d >= -FTINY && d <= FTINY)
316 +                return(0.);
317 +        dist = (DOT(pos, onorm) - offs)/d;
318 +        if (dist < 0.)
319 +                return(0.);
320 +        for (i = 0; i < 3; i++)
321 +                oc[i] = pos[i] + dist*sp->aim[i];
322 +        return(sp->siz*dist*dist/PI/(d*d));
323 + }
324 +
325 +
326 + double
327 + beamdisk(oc, op, sp, dir)       /* intersect beam with object op */
328 + FVECT  oc;
329 + OBJREC  *op;
330 + register SPOT  *sp;
331 + FVECT  dir;
332 + {
333 +        FVECT  onorm;
334 +        double  offs, d, dist;
335 +        register int  i;
336 +
337 +        offs = getplaneq(onorm, op);
338 +        d = -DOT(onorm, dir);
339 +        if (d >= -FTINY && d <= FTINY)
340 +                return(0.);
341 +        dist = (DOT(sp->aim, onorm) - offs)/d;
342 +        for (i = 0; i < 3; i++)
343 +                oc[i] = sp->aim[i] + dist*dir[i];
344 +        return(sp->siz/PI/(d*d));
345 + }
346 +
347 +
348 + double
349   intercircle(cc, c1, c2, r1s, r2s)       /* intersect two circles */
350   FVECT  cc;                      /* midpoint (return value) */
351   FVECT  c1, c2;                  /* circle centers */
# Line 341 | Line 394 | register RAY  *r;
394                  first = 0; last = nsources-1;
395          }
396          for (i = first; i <= last; i++)
397 <                if (source[i].sflags & SDISTANT)
397 >                if ((source[i].sflags & (SDISTANT|SVIRTUAL)) == SDISTANT)
398                          /*
399                           * Check to see if ray is within
400                           * solid angle of source.
# Line 364 | Line 417 | register RAY  *r;
417   }
418  
419  
420 < #define  wrongsource(m, r)      (m->otype!=MAT_ILLUM && \
421 <                                r->rsrc>=0 && \
422 <                                source[r->rsrc].so!=r->ro)
420 > #define  wrongsource(m, r)      (r->rsrc>=0 && \
421 >                                source[r->rsrc].so!=r->ro && \
422 >                                (m->otype!=MAT_ILLUM || \
423 >                        objptr(source[r->rsrc].so->omod)->otype==MAT_ILLUM))
424  
425 + #define  distglow(m, r)         (m->otype==MAT_GLOW && \
426 +                                r->rot > m->oargs.farg[3])
427 +
428   #define  badambient(m, r)       ((r->crtype&(AMBIENT|SHADOW))==AMBIENT && \
429 <                                !(m->otype==MAT_GLOW&&r->rot>m->oargs.farg[3]))
429 >                                !distglow(m, r))
430  
431   #define  passillum(m, r)        (m->otype==MAT_ILLUM && \
432                                  !(r->rsrc>=0&&source[r->rsrc].so==r->ro))
433  
434 + #define  srcignore(m, r)        (directinvis && !(r->crtype&SHADOW) && \
435 +                                !distglow(m, r))
436  
437 +
438   m_light(m, r)                   /* ray hit a light source */
439   register OBJREC  *m;
440   register RAY  *r;
# Line 384 | Line 444 | register RAY  *r;
444                  return;
445                                                  /* check for passed illum */
446          if (passillum(m, r)) {
387
447                  if (m->oargs.nsargs < 1 || !strcmp(m->oargs.sarg[0], VOIDID))
448                          raytrans(r);
449                  else
450                          rayshade(r, modifier(m->oargs.sarg[0]));
451 <
452 <                                                /* otherwise treat as source */
453 <        } else {
451 >                return;
452 >        }
453 >                                        /* otherwise treat as source */
454                                                  /* check for behind */
455 <                if (r->rod < 0.0)
456 <                        return;
455 >        if (r->rod < 0.0)
456 >                return;
457 >                                                /* check for invisibility */
458 >        if (srcignore(m, r))
459 >                return;
460                                                  /* get distribution pattern */
461 <                raytexture(r, m->omod);
461 >        raytexture(r, m->omod);
462                                                  /* get source color */
463 <                setcolor(r->rcol, m->oargs.farg[0],
464 <                                  m->oargs.farg[1],
465 <                                  m->oargs.farg[2]);
463 >        setcolor(r->rcol, m->oargs.farg[0],
464 >                          m->oargs.farg[1],
465 >                          m->oargs.farg[2]);
466                                                  /* modify value */
467 <                multcolor(r->rcol, r->pcol);
406 <        }
467 >        multcolor(r->rcol, r->pcol);
468   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines