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

Comparing ray/src/rt/rv3.c (file contents):
Revision 1.10 by greg, Tue Jan 9 09:07:33 1990 UTC vs.
Revision 1.19 by greg, Fri May 3 16:12:38 1991 UTC

# Line 18 | Line 18 | static char SCCSid[] = "$SunId$ LBL";
18  
19   #include  "random.h"
20  
21 + #ifndef WFLUSH
22 + #define WFLUSH          30              /* flush after this many rays */
23 + #endif
24  
25 +
26   getrect(s, r)                           /* get a box */
27   char  *s;
28   register RECT  *r;
# Line 89 | Line 93 | double  *mp;
93                  (*dev->comout)("Pick view center\n");
94                  if ((*dev->getcur)(&x, &y) == ABORT)
95                          return(-1);
96 <                viewray(thisray.rorg, thisray.rdir, &ourview,
97 <                                (x+.5)/hresolu, (y+.5)/vresolu);
96 >                if (viewray(thisray.rorg, thisray.rdir, &ourview,
97 >                                (x+.5)/hresolu, (y+.5)/vresolu) < 0) {
98 >                        error(COMMAND, "not on image");
99 >                        return(-1);
100 >                }
101                  if (!direc || ourview.type == VT_PAR) {
102                          rayorigin(&thisray, NULL, PRIMARY, 1.0);
103                          if (!localhit(&thisray, &thescene)) {
# Line 130 | Line 137 | paint(p, xmin, ymin, xmax, ymax)       /* compute and paint
137   register PNODE  *p;
138   int  xmin, ymin, xmax, ymax;
139   {
140 +        extern long  nrays;
141 +        static long  lastflush = 0;
142          static RAY  thisray;
143          double  h, v;
135        register int  i;
144  
145          if (xmax - xmin <= 0 || ymax - ymin <= 0) {     /* empty */
146                  p->x = xmin;
# Line 141 | Line 149 | int  xmin, ymin, xmax, ymax;
149                  return;
150          }
151                                                  /* jitter ray direction */
152 <        p->x = h = xmin + (xmax-xmin)*frandom();
153 <        h /= hresolu;
146 <        p->y = v = ymin + (ymax-ymin)*frandom();
147 <        v /= vresolu;
152 >        h = xmin + (xmax-xmin)*frandom();
153 >        v = ymin + (ymax-ymin)*frandom();
154          
155 <        viewray(thisray.rorg, thisray.rdir, &ourview, h, v);
155 >        if (viewray(thisray.rorg, thisray.rdir, &ourview,
156 >                        h/hresolu, v/vresolu) < 0) {
157 >                setcolor(thisray.rcol, 0.0, 0.0, 0.0);
158 >        } else {
159 >                rayorigin(&thisray, NULL, PRIMARY, 1.0);
160 >                rayvalue(&thisray);
161 >        }
162  
163 <        rayorigin(&thisray, NULL, PRIMARY, 1.0);
164 <        
153 <        rayvalue(&thisray);
154 <
163 >        p->x = h;
164 >        p->y = v;
165          copycolor(p->v, thisray.rcol);
156
166          scalecolor(p->v, exposure);
167  
168          (*dev->paintr)(greyscale?greyof(p->v):p->v, xmin, ymin, xmax, ymax);
169 +
170 +        if (dev->flush != NULL && nrays - lastflush >= WFLUSH) {
171 +                lastflush = nrays;
172 +                (*dev->flush)();
173 +        }
174   }
175  
176  
# Line 164 | Line 178 | newimage()                             /* start a new image */
178   {
179                                                  /* free old image */
180          freepkids(&ptrunk);
181 +                                                /* save reserve memory */
182 +        fillreserves();
183                                                  /* compute resolution */
184          hresolu = dev->xsiz;
185          vresolu = dev->ysiz;
186 <        normaspect(&ourview, &dev->pixaspect, &hresolu, &vresolu);
186 >        normaspect(viewaspect(&ourview), &dev->pixaspect, &hresolu, &vresolu);
187          pframe.l = pframe.d = 0;
188          pframe.r = hresolu; pframe.u = vresolu;
189          pdepth = 0;
# Line 346 | Line 362 | register VIEW  *vp;
362          if ((err = setview(vp)) != NULL) {
363                  sprintf(errmsg, "view not set - %s", err);
364                  error(COMMAND, errmsg);
365 <        } else if (bcmp(vp, &ourview, sizeof(VIEW))) {
366 <                copyview(&oldview, &ourview);
367 <                copyview(&ourview, vp);
368 <                newimage();             /* newimage() calls with vp=&ourview! */
365 >        } else if (bcmp((char *)vp, (char *)&ourview, sizeof(VIEW))) {
366 >                copystruct(&oldview, &ourview);
367 >                copystruct(&ourview, vp);
368 >                newimage();
369          }
370   }
371  
# Line 389 | Line 405 | FVECT  vc;
405   }
406  
407  
408 < spinvector(vres, vorig, vnorm, theta)   /* rotate vector around normal */
409 < FVECT  vres, vorig, vnorm;
410 < double  theta;
408 > zoomview(vp, zf)                        /* zoom in our out */
409 > register VIEW  *vp;
410 > double  zf;
411   {
412 <        extern double  sin(), cos();
413 <        double  sint, cost, dotp;
414 <        FVECT  vperp;
415 <        register int  i;
416 <        
401 <        if (theta == 0.0) {
402 <                VCOPY(vres, vorig);
412 >        switch (vp->type) {
413 >        case VT_PAR:                            /* parallel view */
414 >        case VT_ANG:                            /* angular fisheye */
415 >                vp->horiz /= zf;
416 >                vp->vert /= zf;
417                  return;
418 +        case VT_PER:                            /* perspective view */
419 +                vp->horiz = atan(tan(vp->horiz*(PI/180./2.))/zf) /
420 +                                (PI/180./2.);
421 +                vp->vert = atan(tan(vp->vert*(PI/180./2.))/zf) /
422 +                                (PI/180./2.);
423 +                return;
424 +        case VT_HEM:                            /* hemispherical fisheye */
425 +                vp->horiz = sin(vp->horiz*(PI/180./2.))/zf;
426 +                if (vp->horiz >= 1.0-FTINY)
427 +                        vp->horiz = 180.;
428 +                else
429 +                        vp->horiz = asin(vp->horiz) / (PI/180./2.);
430 +                vp->vert = sin(vp->vert*(PI/180./2.))/zf;
431 +                if (vp->vert >= 1.0-FTINY)
432 +                        vp->vert = 180.;
433 +                else
434 +                        vp->vert = asin(vp->vert) / (PI/180./2.);
435 +                return;
436          }
405        sint = sin(theta);
406        cost = cos(theta);
407        dotp = DOT(vorig, vnorm);
408        fcross(vperp, vnorm, vorig);
409        for (i = 0; i < 3; i++)
410                vres[i] = vnorm[i]*dotp*(1.-cost) +
411                                vorig[i]*cost + vperp[i]*sint;
437   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines