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

Comparing ray/src/rt/raytrace.c (file contents):
Revision 2.44 by greg, Wed Dec 31 01:50:02 2003 UTC vs.
Revision 2.97 by greg, Fri Jun 20 23:21:33 2025 UTC

# Line 10 | Line 10 | static const char RCSid[] = "$Id$";
10   #include "copyright.h"
11  
12   #include  "ray.h"
13 <
13 > #include  "source.h"
14   #include  "otypes.h"
15
15   #include  "otspecial.h"
16 + #include  "random.h"
17 + #include  "pmap.h"
18  
19   #define  MAXCSET        ((MAXSET+1)*2-1)        /* maximum check set size */
20  
21 < unsigned long  raynum = 0;              /* next unique ray number */
22 < unsigned long  nrays = 0;               /* number of calls to localhit */
21 > RNUMBER  raynum = 0;            /* next unique ray number */
22 > RNUMBER  nrays = 0;             /* number of calls to localhit */
23  
24   static RREAL  Lambfa[5] = {PI, PI, PI, 0.0, 0.0};
25   OBJREC  Lamb = {
26          OVOID, MAT_PLASTIC, "Lambertian",
27 <        {0, 5, NULL, Lambfa}, NULL,
27 >        {NULL, Lambfa, 0, 5}, NULL
28   };                                      /* a Lambertian surface */
29  
30   OBJREC  Aftplane;                       /* aft clipping plane object */
31  
31 static int  raymove(), checkhit();
32 static void  checkset();
33
32   #define  RAYHIT         (-1)            /* return value for intercepted ray */
33  
34 + static int raymove(FVECT  pos, OBJECT  *cxs, int  dirf, RAY  *r, CUBE  *cu);
35 + static int checkhit(RAY  *r, CUBE  *cu, OBJECT  *cxs);
36 + static void checkset(OBJECT  *os, OBJECT  *cs);
37  
38 +
39   int
40 < rayorigin(r, ro, rt, rw)                /* start new ray from old one */
41 < register RAY  *r, *ro;
42 < int  rt;
43 < double  rw;
40 > rayorigin(              /* start new ray from old one */
41 >        RAY  *r,
42 >        int  rt,
43 >        const RAY  *ro,
44 >        const SCOLOR rc
45 > )
46   {
47 <        double  re;
48 <
47 >        double  rw, re;
48 >                                                /* assign coefficient/weight */
49 >        if (rc == NULL) {
50 >                rw = 1.0;
51 >                setscolor(r->rcoef, 1., 1., 1.);
52 >        } else {
53 >                rw = sintens((COLORV *)rc);
54 >                if (rw > 1.0)
55 >                        rw = 1.0;               /* avoid calculation growth */
56 >                if (rc != r->rcoef)
57 >                        copyscolor(r->rcoef, rc);
58 >        }
59          if ((r->parent = ro) == NULL) {         /* primary ray */
60                  r->rlvl = 0;
61                  r->rweight = rw;
# Line 54 | Line 68 | double  rw;
68                  r->gecc = seccg;
69                  r->slights = NULL;
70          } else {                                /* spawned ray */
71 +                if (ro->rot >= FHUGE*.99) {
72 +                        memset(r, 0, sizeof(RAY));
73 +                        return(-1);             /* illegal continuation */
74 +                }
75                  r->rlvl = ro->rlvl;
76 +                r->rsrc = ro->rsrc;
77                  if (rt & RAYREFL) {
78                          r->rlvl++;
79 <                        r->rsrc = -1;
79 >                        if (r->rsrc >= 0)       /* malfunctioning material? */
80 >                                r->rsrc = -1;
81                          r->clipset = ro->clipset;
82                          r->rmax = 0.0;
83                  } else {
64                        r->rsrc = ro->rsrc;
84                          r->clipset = ro->newcset;
85 <                        r->rmax = ro->rmax <= FTINY ? 0.0 : ro->rmax - ro->rot;
85 >                        r->rmax = (ro->rmax > FTINY)*(ro->rmax - ro->rot);
86                  }
87                  r->revf = ro->revf;
88                  copycolor(r->cext, ro->cext);
# Line 73 | Line 92 | double  rw;
92                  r->crtype = ro->crtype | (r->rtype = rt);
93                  VCOPY(r->rorg, ro->rop);
94                  r->rweight = ro->rweight * rw;
95 <                                                /* estimate absorption */
95 >                                                /* estimate extinction */
96                  re = colval(ro->cext,RED) < colval(ro->cext,GRN) ?
97                                  colval(ro->cext,RED) : colval(ro->cext,GRN);
98                  if (colval(ro->cext,BLU) < re) re = colval(ro->cext,BLU);
99 <                if (re > 0.)
100 <                        r->rweight *= exp(-re*ro->rot);
99 >                re *= ro->rot;
100 >                if (re > 0.1) {
101 >                        if (re > 92.) {
102 >                                r->rweight = 0.0;
103 >                        } else {
104 >                                r->rweight *= exp(-re);
105 >                        }
106 >                }
107          }
108          rayclear(r);
109 <        return(r->rlvl <= maxdepth && r->rweight >= minweight ? 0 : -1);
109 >        if (r->rweight <= 0.0)                  /* check for expiration */
110 >                return(-1);
111 >        if (r->crtype & SHADOW)                 /* shadow commitment */
112 >                return(0);
113 >                                                /* ambient in photon map? */
114 >        if (ro != NULL && ro->crtype & AMBIENT) {
115 >                if (causticPhotonMapping)
116 >                        return(-1);
117 >                if (photonMapping && rt != TRANS)
118 >                        return(-1);
119 >        }
120 >        if ((maxdepth <= 0) & (rc != NULL)) {   /* Russian roulette */
121 >                if (minweight <= 0.0)
122 >                        error(USER, "zero ray weight in Russian roulette");
123 >                if ((maxdepth < 0) & (r->rlvl > -maxdepth))
124 >                        return(-1);             /* upper reflection limit */
125 >                if (r->rweight >= minweight)
126 >                        return(0);
127 >                if (frandom() > r->rweight/minweight)
128 >                        return(-1);
129 >                rw = minweight/r->rweight;      /* promote survivor */
130 >                scalescolor(r->rcoef, rw);
131 >                r->rweight = minweight;
132 >                return(0);
133 >        }
134 >        return((r->rweight >= minweight) & (r->rlvl <= abs(maxdepth)) ? 0 : -1);
135   }
136  
137  
138   void
139 < rayclear(r)                     /* clear a ray for (re)evaluation */
140 < register RAY  *r;
139 > rayclear(                       /* clear a ray for (re)evaluation */
140 >        RAY  *r
141 > )
142   {
143          r->rno = raynum++;
144          r->newcset = r->clipset;
# Line 95 | Line 146 | register RAY  *r;
146          r->robj = OVOID;
147          r->ro = NULL;
148          r->rox = NULL;
149 <        r->rt = r->rot = FHUGE;
149 >        r->rxt = r->rmt = r->rot = FHUGE;
150 >        VCOPY(r->rop, r->rorg);
151 >        r->ron[0] = -r->rdir[0]; r->ron[1] = -r->rdir[1]; r->ron[2] = -r->rdir[2];
152 >        r->rod = 1.0;
153          r->pert[0] = r->pert[1] = r->pert[2] = 0.0;
154 +        r->rflips = 0;
155          r->uv[0] = r->uv[1] = 0.0;
156 <        setcolor(r->pcol, 1.0, 1.0, 1.0);
157 <        setcolor(r->rcol, 0.0, 0.0, 0.0);
156 >        setscolor(r->pcol, 1.0, 1.0, 1.0);
157 >        scolorblack(r->mcol);
158 >        scolorblack(r->rcol);
159   }
160  
161  
162   void
163 < raytrace(r)                     /* trace a ray and compute its value */
164 < RAY  *r;
163 > raytrace(                       /* trace a ray and compute its value */
164 >        RAY  *r
165 > )
166   {
167          if (localhit(r, &thescene))
168                  raycont(r);             /* hit local surface, evaluate */
# Line 115 | Line 172 | RAY  *r;
172          } else if (sourcehit(r))
173                  rayshade(r, r->ro->omod);       /* distant source */
174  
118        rayparticipate(r);              /* for participating medium */
119
175          if (trace != NULL)
176                  (*trace)(r);            /* trace execution */
177 +
178 +        rayparticipate(r);              /* for participating medium */
179   }
180  
181  
182   void
183 < raycont(r)                      /* check for clipped object and continue */
184 < register RAY  *r;
183 > raycont(                        /* check for clipped object and continue */
184 >        RAY  *r
185 > )
186   {
187          if ((r->clipset != NULL && inset(r->clipset, r->ro->omod)) ||
188                          !rayshade(r, r->ro->omod))
# Line 133 | Line 191 | register RAY  *r;
191  
192  
193   void
194 < raytrans(r)                     /* transmit ray as is */
195 < register RAY  *r;
194 > raytrans(                       /* transmit ray as is */
195 >        RAY  *r
196 > )
197   {
198          RAY  tr;
199  
200 <        if (rayorigin(&tr, r, TRANS, 1.0) == 0) {
201 <                VCOPY(tr.rdir, r->rdir);
202 <                rayvalue(&tr);
203 <                copycolor(r->rcol, tr.rcol);
204 <                r->rt = r->rot + tr.rt;
200 >        rayorigin(&tr, TRANS, r, NULL);         /* always continue */
201 >        VCOPY(tr.rdir, r->rdir);
202 >        rayvalue(&tr);
203 >        copyscolor(r->mcol, tr.mcol);
204 >        copyscolor(r->rcol, tr.rcol);
205 >        r->rmt = r->rot + tr.rmt;
206 >        r->rxt = r->rot + tr.rxt;
207 > }
208 >
209 >
210 > int
211 > raytirrad(                      /* irradiance hack */
212 >        OBJREC  *m,
213 >        RAY     *r
214 > )
215 > {
216 >        if (m->otype != MAT_CLIP && ismaterial(m->otype)) {
217 >                if (istransp(m) || isBSDFproxy(m)) {
218 >                        raytrans(r);
219 >                        return(1);
220 >                }
221 >                if (!islight(m->otype)) {
222 >                        setscolor(r->pcol, 1.0, 1.0, 1.0);
223 >                        return((*ofun[Lamb.otype].funp)(&Lamb, r));
224 >                }
225          }
226 +        return(0);              /* not a qualifying surface */
227   }
228  
229  
230   int
231 < rayshade(r, mod)                /* shade ray r with material mod */
232 < register RAY  *r;
233 < int  mod;
231 > rayshade(               /* shade ray r with material mod */
232 >        RAY  *r,
233 >        int  mod
234 > )
235   {
236 <        int  gotmat;
237 <        register OBJREC  *m;
238 <        r->rt = r->rot;                 /* set effective ray length */
239 <        for (gotmat = 0; !gotmat && mod != OVOID; mod = m->omod) {
236 >        int     tst_irrad = do_irrad && !(r->crtype & ~(PRIMARY|TRANS));
237 >        OBJREC  *m;
238 >
239 >        r->rxt = r->rot;                /* preset effective ray length */
240 >        for ( ; mod != OVOID; mod = m->omod) {
241                  m = objptr(mod);
242                  /****** unnecessary test since modifier() is always called
243                  if (!ismodifier(m->otype)) {
# Line 164 | Line 246 | int  mod;
246                  }
247                  ******/
248                                          /* hack for irradiance calculation */
249 <                if (do_irrad && !(r->crtype & ~(PRIMARY|TRANS)) &&
250 <                                m->otype != MAT_CLIP &&
251 <                                (ofun[m->otype].flags & (T_M|T_X))) {
252 <                        if (irr_ignore(m->otype)) {
253 <                                raytrans(r);
172 <                                return(1);
173 <                        }
174 <                        if (!islight(m->otype))
175 <                                m = &Lamb;
176 <                }
177 <                                        /* materials call raytexture */
178 <                gotmat = (*ofun[m->otype].funp)(m, r);
249 >                if (tst_irrad && raytirrad(m, r))
250 >                        return(1);
251 >
252 >                if ((*ofun[m->otype].funp)(m, r))
253 >                        return(1);      /* materials call raytexture() */
254          }
255 <        return(gotmat);
255 >        return(0);                      /* no material! */
256   }
257  
258  
259   void
260 < rayparticipate(r)                       /* compute ray medium participation */
261 < register RAY  *r;
260 > rayparticipate(                 /* compute ray medium participation */
261 >        RAY  *r
262 > )
263   {
264 <        COLOR   ce, ca;
264 >        COLOR   ce;
265          double  re, ge, be;
266  
267          if (intens(r->cext) <= 1./FHUGE)
# Line 198 | Line 274 | register RAY  *r;
274                  ge *= 1. - colval(r->albedo,GRN);
275                  be *= 1. - colval(r->albedo,BLU);
276          }
277 <        setcolor(ce,    re<=0. ? 1. : re>92. ? 0. : exp(-re),
278 <                        ge<=0. ? 1. : ge>92. ? 0. : exp(-ge),
279 <                        be<=0. ? 1. : be>92. ? 0. : exp(-be));
280 <        multcolor(r->rcol, ce);                 /* path absorption */
277 >        setcolor(ce,    re<=FTINY ? 1. : re>92. ? 0. : exp(-re),
278 >                        ge<=FTINY ? 1. : ge>92. ? 0. : exp(-ge),
279 >                        be<=FTINY ? 1. : be>92. ? 0. : exp(-be));
280 >        smultcolor(r->rcol, ce);                /* path extinction */
281          if (r->crtype & SHADOW || intens(r->albedo) <= FTINY)
282                  return;                         /* no scattering */
283 <        setcolor(ca,
284 <                colval(r->albedo,RED)*colval(ambval,RED)*(1.-colval(ce,RED)),
285 <                colval(r->albedo,GRN)*colval(ambval,GRN)*(1.-colval(ce,GRN)),
286 <                colval(r->albedo,BLU)*colval(ambval,BLU)*(1.-colval(ce,BLU)));
287 <        addcolor(r->rcol, ca);                  /* ambient in scattering */
283 >        
284 >        /* PMAP: indirect inscattering accounted for by volume photons? */
285 >        if (!volumePhotonMapping) {
286 >                SCOLOR  ca;
287 >                setscolor(ca,
288 >                        colval(r->albedo,RED)*colval(ambval,RED)*(1.-colval(ce,RED)),
289 >                        colval(r->albedo,GRN)*colval(ambval,GRN)*(1.-colval(ce,GRN)),
290 >                        colval(r->albedo,BLU)*colval(ambval,BLU)*(1.-colval(ce,BLU)));
291 >                saddscolor(r->rcol, ca);        /* ambient in scattering */
292 >        }
293 >        
294          srcscatter(r);                          /* source in scattering */
295   }
296  
297  
298   void
299 < raytexture(r, mod)                      /* get material modifiers */
300 < RAY  *r;
301 < OBJECT  mod;
299 > raytexture(                     /* get material modifiers */
300 >        RAY  *r,
301 >        OBJECT  mod
302 > )
303   {
304 <        register OBJREC  *m;
304 >        OBJREC  *m;
305                                          /* execute textures and patterns */
306          for ( ; mod != OVOID; mod = m->omod) {
307                  m = objptr(mod);
# Line 238 | Line 321 | OBJECT  mod;
321  
322  
323   int
324 < raymixture(r, fore, back, coef)         /* mix modifiers */
325 < register RAY  *r;
326 < OBJECT  fore, back;
327 < double  coef;
324 > raymixture(             /* mix modifiers */
325 >        RAY  *r,
326 >        OBJECT  fore,
327 >        OBJECT  back,
328 >        double  coef
329 > )
330   {
331          RAY  fr, br;
332 +        double  mfore, mback;
333          int  foremat, backmat;
334 <        register int  i;
334 >        int  i;
335                                          /* bound coefficient */
336          if (coef > 1.0)
337                  coef = 1.0;
# Line 255 | Line 341 | double  coef;
341          foremat = backmat = 0;
342                                          /* foreground */
343          fr = *r;
344 <        if (coef > FTINY)
344 >        if (coef > FTINY) {
345 >                fr.rweight *= coef;
346 >                scalescolor(fr.rcoef, coef);
347                  foremat = rayshade(&fr, fore);
348 +        }
349                                          /* background */
350          br = *r;
351 <        if (coef < 1.0-FTINY)
351 >        if (coef < 1.0-FTINY) {
352 >                br.rweight *= 1.0-coef;
353 >                scalescolor(br.rcoef, 1.0-coef);
354                  backmat = rayshade(&br, back);
355 +        }
356                                          /* check for transparency */
357          if (backmat ^ foremat) {
358                  if (backmat && coef > FTINY)
# Line 272 | Line 364 | double  coef;
364          for (i = 0; i < 3; i++)
365                  r->pert[i] = coef*fr.pert[i] + (1.0-coef)*br.pert[i];
366                                          /* mix pattern colors */
367 <        scalecolor(fr.pcol, coef);
368 <        scalecolor(br.pcol, 1.0-coef);
369 <        copycolor(r->pcol, fr.pcol);
370 <        addcolor(r->pcol, br.pcol);
367 >        scalescolor(fr.pcol, coef);
368 >        scalescolor(br.pcol, 1.0-coef);
369 >        copyscolor(r->pcol, fr.pcol);
370 >        saddscolor(r->pcol, br.pcol);
371                                          /* return value tells if material */
372          if (!foremat & !backmat)
373                  return(0);
374                                          /* mix returned ray values */
375 <        scalecolor(fr.rcol, coef);
376 <        scalecolor(br.rcol, 1.0-coef);
377 <        copycolor(r->rcol, fr.rcol);
378 <        addcolor(r->rcol, br.rcol);
379 <        r->rt = bright(fr.rcol) > bright(br.rcol) ? fr.rt : br.rt;
375 >        scalescolor(fr.rcol, coef);
376 >        scalescolor(br.rcol, 1.0-coef);
377 >        copyscolor(r->rcol, fr.rcol);
378 >        saddscolor(r->rcol, br.rcol);
379 >        scalescolor(fr.mcol, coef);
380 >        scalescolor(br.mcol, 1.0-coef);
381 >        copyscolor(r->mcol, fr.mcol);
382 >        saddscolor(r->mcol, br.mcol);
383 >        mfore = pbright(fr.mcol); mback = pbright(br.mcol);
384 >        r->rmt = mfore > mback ? fr.rmt : br.rmt;
385 >        r->rxt = pbright(fr.rcol)-mfore > pbright(br.rcol)-mback ?
386 >                        fr.rxt : br.rxt;
387          return(1);
388   }
389  
390  
391   double
392 < raydist(r, flags)               /* compute (cumulative) ray distance */
393 < register RAY  *r;
394 < register int  flags;
392 > raydist(                /* compute (cumulative) ray distance */
393 >        const RAY  *r,
394 >        int  flags
395 > )
396   {
397          double  sum = 0.0;
398  
# Line 304 | Line 404 | register int  flags;
404   }
405  
406  
407 + void
408 + raycontrib(             /* compute (cumulative) ray contribution */
409 +        SCOLOR  rc,
410 +        const RAY  *r,
411 +        int  flags
412 + )
413 + {
414 +        static int      warnedPM = 0;
415 +        double          re, ge, be;
416 +        SCOLOR          ce;
417 +
418 +        setscolor(rc, 1., 1., 1.);
419 +        re = ge = be = 0.;
420 +
421 +        while (r != NULL && r->crtype&flags) {
422 +                                        /* include this ray coefficient */
423 +                smultscolor(rc, r->rcoef);
424 +                                        /* check participating medium */
425 +                if (!warnedPM && bright(r->albedo) > FTINY) {
426 +                        error(WARNING,
427 +        "ray contribution calculation does not support participating media");
428 +                        warnedPM++;
429 +                }
430 +                                        /* sum PM extinction */
431 +                re += r->rot*colval(r->cext,RED);
432 +                ge += r->rot*colval(r->cext,GRN);
433 +                be += r->rot*colval(r->cext,BLU);
434 +                                        /* descend the tree */
435 +                r = r->parent;
436 +        }
437 +                                        /* cumulative extinction */
438 +        setscolor(ce,   re<=FTINY ? 1. : re>92. ? 0. : exp(-re),
439 +                        ge<=FTINY ? 1. : ge>92. ? 0. : exp(-ge),
440 +                        be<=FTINY ? 1. : be>92. ? 0. : exp(-be));
441 +        smultscolor(rc, ce);
442 + }
443 +
444 +
445   double
446 < raynormal(norm, r)              /* compute perturbed normal for ray */
447 < FVECT  norm;
448 < register RAY  *r;
446 > raynormal(              /* compute perturbed normal for ray */
447 >        FVECT  norm,
448 >        RAY  *r
449 > )
450   {
451          double  newdot;
452 <        register int  i;
452 >        int  i;
453  
454          /*      The perturbation is added to the surface normal to obtain
455           *  the new normal.  If the new normal would affect the surface
# Line 330 | Line 469 | register RAY  *r;
469                  return(r->rod);
470          }
471          newdot = -DOT(norm, r->rdir);
472 <        if ((newdot > 0.0) != (r->rod > 0.0)) {         /* fix orientation */
472 >        if ((newdot > 0.0) ^ (r->rod > 0.0)) {          /* fix orientation */
473                  for (i = 0; i < 3; i++)
474                          norm[i] += 2.0*newdot*r->rdir[i];
475                  newdot = -newdot;
# Line 340 | Line 479 | register RAY  *r;
479  
480  
481   void
482 < newrayxf(r)                     /* get new tranformation matrix for ray */
483 < RAY  *r;
482 > newrayxf(                       /* get new tranformation matrix for ray */
483 >        RAY  *r
484 > )
485   {
486          static struct xfn {
487                  struct xfn  *next;
488                  FULLXF  xf;
489          }  xfseed = { &xfseed }, *xflast = &xfseed;
490 <        register struct xfn  *xp;
491 <        register RAY  *rp;
490 >        struct xfn  *xp;
491 >        const RAY  *rp;
492  
493          /*
494           * Search for transform in circular list that
# Line 359 | Line 499 | RAY  *r;
499                  if (rp->rox == &xp->xf) {               /* xp in use */
500                          xp = xp->next;                  /* move to next */
501                          if (xp == xflast) {             /* need new one */
502 <                                xp = (struct xfn *)malloc(sizeof(struct xfn));
502 >                                xp = (struct xfn *)bmalloc(sizeof(struct xfn));
503                                  if (xp == NULL)
504                                          error(SYSTEM,
505                                                  "out of memory in newrayxf");
# Line 377 | Line 517 | RAY  *r;
517  
518  
519   void
520 < flipsurface(r)                  /* reverse surface orientation */
521 < register RAY  *r;
520 > flipsurface(                    /* reverse surface orientation */
521 >        RAY  *r
522 > )
523   {
524          r->rod = -r->rod;
525          r->ron[0] = -r->ron[0];
# Line 387 | Line 528 | register RAY  *r;
528          r->pert[0] = -r->pert[0];
529          r->pert[1] = -r->pert[1];
530          r->pert[2] = -r->pert[2];
531 +        r->rflips++;
532   }
533  
534  
535 + int
536 + rayreject(              /* check if candidate hit is worse than current */
537 +        OBJREC *o,
538 +        RAY *r,
539 +        double t,
540 +        double rod
541 + )
542 + {
543 +        OBJREC  *mnew, *mray;
544 +
545 +        if ((t <= FTINY) | (t > r->rot + FTINY))
546 +                return(1);
547 +        if (t < r->rot - FTINY)         /* is new hit significantly closer? */
548 +                return(0);
549 +                                        /* coincident point, so decide... */
550 +        if (o == r->ro)
551 +                return(1);              /* shouldn't happen */
552 +        if (r->ro == NULL)
553 +                return(0);              /* ditto */
554 +        mnew = findmaterial(o);
555 +        mray = findmaterial(r->ro);     /* check material transparencies */
556 +        if (mnew == NULL) {
557 +                if (mray != NULL)
558 +                        return(1);      /* old has material, new does not */
559 +        } else if (mray == NULL) {
560 +                return(0);              /* new has material, old does not */
561 +        } else if (istransp(mnew)) {
562 +                if (!istransp(mray))
563 +                        return(1);      /* new is transparent, old is not */
564 +        } else if (istransp(mray)) {
565 +                return(0);              /* old is transparent, new is not */
566 +        }
567 +        if (rod <= 0) {                 /* check which side we hit */
568 +                if (r->rod > 0)
569 +                        return(1);      /* old hit front, new did not */
570 +        } else if (r->rod <= 0) {
571 +                return(0);              /* new hit front, old did not */
572 +        }
573 +                        /* earlier modifier definition wins tie */
574 +        return (r->ro->omod >= o->omod);
575 + }
576 +
577   void
578 < rayhit(oset, r)                 /* standard ray hit test */
579 < OBJECT  *oset;
580 < RAY  *r;
578 > rayhit(                 /* standard ray hit test */
579 >        OBJECT  *oset,
580 >        RAY  *r
581 > )
582   {
583          OBJREC  *o;
584          int     i;
# Line 407 | Line 592 | RAY  *r;
592  
593  
594   int
595 < localhit(r, scene)              /* check for hit in the octree */
596 < register RAY  *r;
597 < register CUBE  *scene;
595 > localhit(               /* check for hit in the octree */
596 >        RAY  *r,
597 >        CUBE  *scene
598 > )
599   {
600          OBJECT  cxset[MAXCSET+1];       /* set of checked objects */
601          FVECT  curpos;                  /* current cube position */
602          int  sflags;                    /* sign flags */
603          double  t, dt;
604 <        register int  i;
604 >        int  i;
605  
606          nrays++;                        /* increment trace counter */
607          sflags = 0;
# Line 426 | Line 612 | register CUBE  *scene;
612                  else if (r->rdir[i] < -1e-7)
613                          sflags |= 0x10 << i;
614          }
615 <        if (sflags == 0)
616 <                error(CONSISTENCY, "zero ray direction in localhit");
615 >        if (!sflags) {
616 >                error(WARNING, "zero ray direction in localhit");
617 >                return(0);
618 >        }
619                                          /* start off assuming nothing hit */
620          if (r->rmax > FTINY) {          /* except aft plane if one */
621                  r->ro = &Aftplane;
622                  r->rot = r->rmax;
623 <                for (i = 0; i < 3; i++)
436 <                        r->rop[i] = r->rorg[i] + r->rot*r->rdir[i];
623 >                VSUM(r->rop, r->rorg, r->rdir, r->rot);
624          }
625                                          /* find global cube entrance point */
626          t = 0.0;
# Line 456 | Line 643 | register CUBE  *scene;
643                  if (t >= r->rot)        /* clipped already */
644                          return(0);
645                                          /* advance position */
646 <                for (i = 0; i < 3; i++)
460 <                        curpos[i] += r->rdir[i]*t;
646 >                VSUM(curpos, curpos, r->rdir, t);
647  
648                  if (!incube(scene, curpos))     /* non-intersecting ray */
649                          return(0);
# Line 469 | Line 655 | register CUBE  *scene;
655  
656  
657   static int
658 < raymove(pos, cxs, dirf, r, cu)          /* check for hit as we move */
659 < FVECT  pos;                     /* current position, modified herein */
660 < OBJECT  *cxs;                   /* checked objects, modified by checkhit */
661 < int  dirf;                      /* direction indicators to speed tests */
662 < register RAY  *r;
663 < register CUBE  *cu;
658 > raymove(                /* check for hit as we move */
659 >        FVECT  pos,                     /* current position, modified herein */
660 >        OBJECT  *cxs,                   /* checked objects, modified by checkhit */
661 >        int  dirf,                      /* direction indicators to speed tests */
662 >        RAY  *r,
663 >        CUBE  *cu
664 > )
665   {
666          int  ax;
667          double  dt, t;
668  
669          if (istree(cu->cutree)) {               /* recurse on subcubes */
670                  CUBE  cukid;
671 <                register int  br, sgn;
671 >                int  br, sgn;
672  
673                  cukid.cusize = cu->cusize * 0.5;        /* find subcube */
674                  VCOPY(cukid.cuorg, cu->cuorg);
# Line 547 | Line 734 | register CUBE  *cu;
734                          ax = 2;
735                  }
736          }
737 <        pos[0] += r->rdir[0]*t;
551 <        pos[1] += r->rdir[1]*t;
552 <        pos[2] += r->rdir[2]*t;
737 >        VSUM(pos, pos, r->rdir, t);
738          return(ax);
739   }
740  
741  
742   static int
743 < checkhit(r, cu, cxs)            /* check for hit in full cube */
744 < register RAY  *r;
745 < CUBE  *cu;
746 < OBJECT  *cxs;
743 > checkhit(               /* check for hit in full cube */
744 >        RAY  *r,
745 >        CUBE  *cu,
746 >        OBJECT  *cxs
747 > )
748   {
749          OBJECT  oset[MAXSET+1];
750  
# Line 575 | Line 761 | OBJECT  *cxs;
761  
762  
763   static void
764 < checkset(os, cs)                /* modify checked set and set to check */
765 < register OBJECT  *os;                   /* os' = os - cs */
766 < register OBJECT  *cs;                   /* cs' = cs + os */
764 > checkset(               /* modify checked set and set to check */
765 >        OBJECT  *os,                    /* os' = os - cs */
766 >        OBJECT  *cs                     /* cs' = cs + os */
767 > )
768   {
769          OBJECT  cset[MAXCSET+MAXSET+1];
770 <        register int  i, j;
770 >        int  i, j;
771          int  k;
772                                          /* copy os in place, cset <- cs */
773          cset[0] = 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines