--- ray/src/rt/rv3.c 1991/11/12 17:09:47 2.1 +++ ray/src/rt/rv3.c 2003/02/25 02:47:23 2.11 @@ -1,28 +1,36 @@ -/* Copyright (c) 1987 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: rv3.c,v 2.11 2003/02/25 02:47:23 greg Exp $"; #endif - /* * rv3.c - miscellaneous routines for rview. * - * 5/11/87 + * External symbols declared in rpaint.h */ +#include "copyright.h" + #include "ray.h" -#include "octree.h" - #include "rpaint.h" #include "random.h" #ifndef WFLUSH -#define WFLUSH 30 /* flush after this many rays */ +#ifdef SPEED +#define WFLUSH (5*SPEED) +#else +#define WFLUSH 100 /* flush after this many rays */ #endif +#endif +#ifdef SMLFLT +#define sscanvec(s,v) (sscanf(s,"%f %f %f",v,v+1,v+2)==3) +#else +#define sscanvec(s,v) (sscanf(s,"%lf %lf %lf",v,v+1,v+2)==3) +#endif + +int getrect(s, r) /* get a box */ char *s; register RECT *r; @@ -69,6 +77,7 @@ register RECT *r; } +int getinterest(s, direc, vec, mp) /* get area of interest */ char *s; int direc; @@ -87,14 +96,14 @@ double *mp; error(COMMAND, "illegal magnification"); return(-1); } - if (sscanf(s, "%*lf %lf %lf %lf", &vec[0], &vec[1], &vec[2]) != 3) { + if (!sscanvec(sskip(s), vec)) { if (dev->getcur == NULL) return(-1); (*dev->comout)("Pick view center\n"); if ((*dev->getcur)(&x, &y) == ABORT) return(-1); - if (viewray(thisray.rorg, thisray.rdir, &ourview, - (x+.5)/hresolu, (y+.5)/vresolu) < 0) { + if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir, + &ourview, (x+.5)/hresolu, (y+.5)/vresolu)) < -FTINY) { error(COMMAND, "not on image"); return(-1); } @@ -133,12 +142,12 @@ register COLOR col; } +void paint(p, xmin, ymin, xmax, ymax) /* compute and paint a rectangle */ register PNODE *p; int xmin, ymin, xmax, ymax; { - extern long nrays; - static long lastflush = 0; + static unsigned long lastflush = 0; static RAY thisray; double h, v; @@ -152,8 +161,8 @@ int xmin, ymin, xmax, ymax; h = xmin + (xmax-xmin)*frandom(); v = ymin + (ymax-ymin)*frandom(); - if (viewray(thisray.rorg, thisray.rdir, &ourview, - h/hresolu, v/vresolu) < 0) { + if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir, &ourview, + h/hresolu, v/vresolu)) < -FTINY) { setcolor(thisray.rcol, 0.0, 0.0, 0.0); } else { rayorigin(&thisray, NULL, PRIMARY, 1.0); @@ -175,6 +184,7 @@ int xmin, ymin, xmax, ymax; } +void newimage() /* start a new image */ { /* free old image */ @@ -195,6 +205,7 @@ newimage() /* start a new image */ } +void redraw() /* redraw the image */ { (*dev->clear)(hresolu, vresolu); @@ -204,6 +215,7 @@ redraw() /* redraw the image */ } +void repaint(xmin, ymin, xmax, ymax) /* repaint a region */ int xmin, ymin, xmax, ymax; { @@ -216,6 +228,7 @@ int xmin, ymin, xmax, ymax; } +void paintrect(p, xmin, ymin, xmax, ymax, r) /* paint picture rectangle */ register PNODE *p; int xmin, ymin, xmax, ymax; @@ -286,6 +299,7 @@ int pd; } +void scalepict(p, sf) /* scale picture values */ register PNODE *p; double sf; @@ -302,6 +316,7 @@ double sf; } +void getpictcolrs(yoff, scan, p, xsiz, ysiz) /* get scanline from picture */ int yoff; register COLR *scan; @@ -332,15 +347,7 @@ int xsiz, ysiz; } -pcopy(p1, p2) /* copy paint node p1 into p2 */ -register PNODE *p1, *p2; -{ - copycolor(p2->v, p1->v); - p2->x = p1->x; - p2->y = p1->y; -} - - +void freepkids(p) /* free pnode's children */ register PNODE *p; { @@ -350,11 +357,12 @@ register PNODE *p; freepkids(p->kid+DR); freepkids(p->kid+UL); freepkids(p->kid+UR); - free((char *)p->kid); + free((void *)p->kid); p->kid = NULL; } +void newview(vp) /* change viewing parameters */ register VIEW *vp; { @@ -371,11 +379,11 @@ register VIEW *vp; } +void moveview(angle, elev, mag, vc) /* move viewpoint */ double angle, elev, mag; FVECT vc; { - extern double sqrt(), dist2(); double d; FVECT v1; VIEW nv; @@ -395,10 +403,20 @@ FVECT vc; d = 0.0; /* don't move closer */ for (i = 0; i < 3; i++) d += (vc[i] - ourview.vp[i])*ourview.vdir[i]; + nv.vfore = ourview.vfore; + nv.vaft = ourview.vaft; } else { nv.horiz = ourview.horiz; nv.vert = ourview.vert; d = sqrt(dist2(ourview.vp, vc)) / mag; + if ((nv.vfore = ourview.vfore) > FTINY) { + nv.vfore += d - d*mag; + if (nv.vfore < 0.0) nv.vfore = 0.0; + } + if ((nv.vaft = ourview.vaft) > FTINY) { + nv.vaft += d - d*mag; + if (nv.vaft <= nv.vfore) nv.vaft = 0.0; + } } for (i = 0; i < 3; i++) nv.vp[i] = vc[i] - d*nv.vdir[i]; @@ -406,15 +424,39 @@ FVECT vc; } -zoomview(vp, zf) /* zoom in our out */ +void +pcopy(p1, p2) /* copy paint node p1 into p2 */ +register PNODE *p1, *p2; +{ + copycolor(p2->v, p1->v); + p2->x = p1->x; + p2->y = p1->y; +} + + +void +zoomview(vp, zf) /* zoom in or out */ register VIEW *vp; double zf; { switch (vp->type) { case VT_PAR: /* parallel view */ + vp->horiz /= zf; + vp->vert /= zf; + return; case VT_ANG: /* angular fisheye */ vp->horiz /= zf; + if (vp->horiz > 360.) + vp->horiz = 360.; vp->vert /= zf; + if (vp->vert > 360.) + vp->vert = 360.; + return; + case VT_CYL: /* cylindrical panorama */ + vp->horiz /= zf; + if (vp->horiz > 360.) + vp->horiz = 360.; + vp->vert = atan(tan(vp->vert*(PI/180./2.))/zf) / (PI/180./2.); return; case VT_PER: /* perspective view */ vp->horiz = atan(tan(vp->horiz*(PI/180./2.))/zf) /