--- ray/src/rt/rv3.c 1990/02/22 11:46:15 1.13 +++ ray/src/rt/rv3.c 1991/05/21 17:41:19 1.20 @@ -93,8 +93,11 @@ double *mp; (*dev->comout)("Pick view center\n"); if ((*dev->getcur)(&x, &y) == ABORT) return(-1); - viewray(thisray.rorg, thisray.rdir, &ourview, - (x+.5)/hresolu, (y+.5)/vresolu); + if (viewray(thisray.rorg, thisray.rdir, &ourview, + (x+.5)/hresolu, (y+.5)/vresolu) < 0) { + error(COMMAND, "not on image"); + return(-1); + } if (!direc || ourview.type == VT_PAR) { rayorigin(&thisray, NULL, PRIMARY, 1.0); if (!localhit(&thisray, &thescene)) { @@ -138,7 +141,6 @@ int xmin, ymin, xmax, ymax; static long lastflush = 0; static RAY thisray; double h, v; - register int i; if (xmax - xmin <= 0 || ymax - ymin <= 0) { /* empty */ p->x = xmin; @@ -147,19 +149,21 @@ int xmin, ymin, xmax, ymax; return; } /* jitter ray direction */ - p->x = h = xmin + (xmax-xmin)*frandom(); - h /= hresolu; - p->y = v = ymin + (ymax-ymin)*frandom(); - v /= vresolu; + h = xmin + (xmax-xmin)*frandom(); + v = ymin + (ymax-ymin)*frandom(); - viewray(thisray.rorg, thisray.rdir, &ourview, h, v); + if (viewray(thisray.rorg, thisray.rdir, &ourview, + h/hresolu, v/vresolu) < 0) { + setcolor(thisray.rcol, 0.0, 0.0, 0.0); + } else { + rayorigin(&thisray, NULL, PRIMARY, 1.0); + samplendx++; + rayvalue(&thisray); + } - rayorigin(&thisray, NULL, PRIMARY, 1.0); - - rayvalue(&thisray); - + p->x = h; + p->y = v; copycolor(p->v, thisray.rcol); - scalecolor(p->v, exposure); (*dev->paintr)(greyscale?greyof(p->v):p->v, xmin, ymin, xmax, ymax); @@ -175,6 +179,8 @@ newimage() /* start a new image */ { /* free old image */ freepkids(&ptrunk); + /* save reserve memory */ + fillreserves(); /* compute resolution */ hresolu = dev->xsiz; vresolu = dev->ysiz; @@ -360,7 +366,7 @@ register VIEW *vp; } else if (bcmp((char *)vp, (char *)&ourview, sizeof(VIEW))) { copystruct(&oldview, &ourview); copystruct(&ourview, vp); - newimage(); /* newimage() calls with vp=&ourview! */ + newimage(); } } @@ -400,24 +406,33 @@ FVECT vc; } -spinvector(vres, vorig, vnorm, theta) /* rotate vector around normal */ -FVECT vres, vorig, vnorm; -double theta; +zoomview(vp, zf) /* zoom in our out */ +register VIEW *vp; +double zf; { - extern double sin(), cos(); - double sint, cost, dotp; - FVECT vperp; - register int i; - - if (theta == 0.0) { - VCOPY(vres, vorig); + switch (vp->type) { + case VT_PAR: /* parallel view */ + case VT_ANG: /* angular fisheye */ + vp->horiz /= zf; + vp->vert /= zf; return; + case VT_PER: /* perspective view */ + vp->horiz = atan(tan(vp->horiz*(PI/180./2.))/zf) / + (PI/180./2.); + vp->vert = atan(tan(vp->vert*(PI/180./2.))/zf) / + (PI/180./2.); + return; + case VT_HEM: /* hemispherical fisheye */ + vp->horiz = sin(vp->horiz*(PI/180./2.))/zf; + if (vp->horiz >= 1.0-FTINY) + vp->horiz = 180.; + else + vp->horiz = asin(vp->horiz) / (PI/180./2.); + vp->vert = sin(vp->vert*(PI/180./2.))/zf; + if (vp->vert >= 1.0-FTINY) + vp->vert = 180.; + else + vp->vert = asin(vp->vert) / (PI/180./2.); + return; } - sint = sin(theta); - cost = cos(theta); - dotp = DOT(vorig, vnorm); - fcross(vperp, vnorm, vorig); - for (i = 0; i < 3; i++) - vres[i] = vnorm[i]*dotp*(1.-cost) + - vorig[i]*cost + vperp[i]*sint; }