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

Comparing ray/src/rt/virtuals.c (file contents):
Revision 1.12 by greg, Tue Jun 25 16:42:05 1991 UTC vs.
Revision 1.16 by greg, Thu Jul 11 16:43:38 1991 UTC

# Line 19 | Line 19 | static char SCCSid[] = "$SunId$ LBL";
19  
20   #include  "random.h"
21  
22 + #define  MINSAMPLES     5               /* minimum number of pretest samples */
23 + #define  STESTMAX       30              /* maximum seeks per sample */
24  
25 +
26   double  getdisk();
27  
28   static OBJECT  *vobject;                /* virtual source objects */
# Line 158 | Line 161 | MAT4  pm;
161                          return(-1);             /* at source!! */
162                  if (source[sn].sflags & SPROX && d > source[sn].sl.prox)
163                          return(-1);             /* too far away */
161                ourspot.siz = 2.*PI*(1. - d/sqrt(d*d+maxrad2));
164                  ourspot.flen = 0.;
165 +                if (d*d > maxrad2)
166 +                        ourspot.siz = 2.*PI*(1. - sqrt(1.-maxrad2/(d*d)));
167 +                else
168 +                        nsflags &= ~SSPOT;
169                  if (source[sn].sflags & SSPOT) {
170                          copystruct(&theirspot, source[sn].sl.s);
171                          multv3(theirspot.aim, source[sn].sl.s->aim, pm);
172 <                        d = ourspot.siz;
173 <                        if (!commonspot(&ourspot, &theirspot, nsloc))
174 <                                return(-1);     /* no overlap */
172 >                        if (nsflags & SSPOT) {
173 >                                ourspot.flen = theirspot.flen;
174 >                                d = ourspot.siz;
175 >                                if (!commonspot(&ourspot, &theirspot, nsloc))
176 >                                        return(-1);     /* no overlap */
177 >                        } else {
178 >                                nsflags |= SSPOT;
179 >                                copystruct(&ourspot, &theirspot);
180 >                                d = 2.*ourspot.siz;
181 >                        }
182                          if (ourspot.siz < d-FTINY) {    /* it shrunk */
183                                  d = spotdisk(v, op, &ourspot, nsloc);
184                                  if (d <= FTINY)
# Line 175 | Line 188 | MAT4  pm;
188                                          VCOPY(ocent, v);
189                                  }
190                          }
178                        ourspot.flen = theirspot.flen;
191                  }
192                  if (source[sn].sflags & SFLAT) {        /* behind source? */
193                          multv3(nsnorm, source[sn].snorm, pm);
# Line 195 | Line 207 | MAT4  pm;
207          if (nsflags & SFLAT)
208                  VCOPY(source[i].snorm, nsnorm);
209          source[i].ss = source[sn].ss; source[i].ss2 = source[sn].ss2;
210 <        if ((source[i].sl.s = (SPOT *)malloc(sizeof(SPOT))) == NULL)
211 <                goto memerr;
212 <        copystruct(source[i].sl.s, &ourspot);
210 >        if (nsflags & SSPOT) {
211 >                if ((source[i].sl.s = (SPOT *)malloc(sizeof(SPOT))) == NULL)
212 >                        goto memerr;
213 >                copystruct(source[i].sl.s, &ourspot);
214 >        }
215          if (nsflags & SPROX)
216                  source[i].sl.prox = source[sn].sl.prox;
217          source[i].sa.svnext = sn;
# Line 253 | Line 267 | register int  sn;      /* target source number */
267          FVECT  offsdir;
268          double  or, d;
269          int  infront;
270 <        int  ssn;
270 >        int  stestlim, ssn;
271          int  nhit, nok;
272          register int  i, n;
273                                  /* return if pretesting disabled */
# Line 272 | Line 286 | register int  sn;      /* target source number */
286                  n = or2/DOT(offsdir,offsdir)*vspretest + .5;
287                  infront = DOT(onorm, offsdir) > 0.;
288          }
289 <        if (n < 1) n = 1;
289 >        if (n < MINSAMPLES) n = MINSAMPLES;
290   #ifdef DEBUG
291          fprintf(stderr, "pretesting source %d in object %s with %d rays\n",
292                          sn, o->oname, n);
293   #endif
294                                  /* sample */
295          or = sqrt(or2);
296 <        ssn = 25*n;
296 >        stestlim = n*STESTMAX;
297 >        ssn = 0;
298          nhit = nok = 0;
299          while (n-- > 0) {
300                                          /* get sample point */
301                  do {
302 <                        if (--ssn < 0) {
302 >                        if (ssn >= stestlim) {
303   #ifdef DEBUG
304                                  fprintf(stderr, "\ttoo hard to hit\n");
305   #endif
# Line 292 | Line 307 | register int  sn;      /* target source number */
307                          }
308                          for (i = 0; i < 3; i++)
309                                  offsdir[i] = or*(1. -
310 <                                                2.*urand(931*i+5827+ssn));
310 >                                        2.*urand(urind(931*i+5827,ssn)));
311 >                        ssn++;
312                          for (i = 0; i < 3; i++)
313                                  sr.rorg[i] = oc[i] + offsdir[i];
314                          d = DOT(offsdir,onorm);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines