--- ray/src/rt/rv3.c 1993/08/05 13:05:01 2.5 +++ ray/src/rt/rv3.c 2003/02/25 02:47:23 2.11 @@ -1,19 +1,16 @@ -/* 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" @@ -33,6 +30,7 @@ static char SCCSid[] = "$SunId$ LBL"; #endif +int getrect(s, r) /* get a box */ char *s; register RECT *r; @@ -79,6 +77,7 @@ register RECT *r; } +int getinterest(s, direc, vec, mp) /* get area of interest */ char *s; int direc; @@ -103,8 +102,8 @@ double *mp; (*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); } @@ -143,11 +142,11 @@ register COLOR col; } +void paint(p, xmin, ymin, xmax, ymax) /* compute and paint a rectangle */ register PNODE *p; int xmin, ymin, xmax, ymax; { - extern unsigned long nrays; static unsigned long lastflush = 0; static RAY thisray; double h, v; @@ -162,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); @@ -185,6 +184,7 @@ int xmin, ymin, xmax, ymax; } +void newimage() /* start a new image */ { /* free old image */ @@ -205,6 +205,7 @@ newimage() /* start a new image */ } +void redraw() /* redraw the image */ { (*dev->clear)(hresolu, vresolu); @@ -214,6 +215,7 @@ redraw() /* redraw the image */ } +void repaint(xmin, ymin, xmax, ymax) /* repaint a region */ int xmin, ymin, xmax, ymax; { @@ -226,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; @@ -296,6 +299,7 @@ int pd; } +void scalepict(p, sf) /* scale picture values */ register PNODE *p; double sf; @@ -312,6 +316,7 @@ double sf; } +void getpictcolrs(yoff, scan, p, xsiz, ysiz) /* get scanline from picture */ int yoff; register COLR *scan; @@ -342,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; { @@ -360,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; { @@ -381,6 +379,7 @@ register VIEW *vp; } +void moveview(angle, elev, mag, vc) /* move viewpoint */ double angle, elev, mag; FVECT vc; @@ -404,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]; @@ -415,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) /