--- ray/src/rt/rv3.c 1991/03/19 13:14:03 1.18 +++ ray/src/rt/rv3.c 1995/01/25 16:08:57 2.8 @@ -1,4 +1,4 @@ -/* Copyright (c) 1987 Regents of the University of California */ +/* Copyright (c) 1994 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -19,10 +19,20 @@ static char SCCSid[] = "$SunId$ LBL"; #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 + getrect(s, r) /* get a box */ char *s; register RECT *r; @@ -87,14 +97,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); } @@ -137,8 +147,8 @@ paint(p, xmin, ymin, xmax, ymax) /* compute and paint register PNODE *p; int xmin, ymin, xmax, ymax; { - extern long nrays; - static long lastflush = 0; + extern unsigned long nrays; + static unsigned long lastflush = 0; static RAY thisray; double h, v; @@ -152,11 +162,12 @@ 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); + samplendx++; rayvalue(&thisray); } @@ -178,6 +189,8 @@ newimage() /* start a new image */ { /* free old image */ freepkids(&ptrunk); + /* save reserve memory */ + fillreserves(); /* compute resolution */ hresolu = dev->xsiz; vresolu = dev->ysiz; @@ -372,7 +385,6 @@ moveview(angle, elev, mag, vc) /* move viewpoint */ double angle, elev, mag; FVECT vc; { - extern double sqrt(), dist2(); double d; FVECT v1; VIEW nv; @@ -392,10 +404,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];