--- ray/src/hd/rhdisp2.c 1998/11/24 12:01:17 3.25 +++ ray/src/hd/rhdisp2.c 1998/12/18 11:56:10 3.29 @@ -17,11 +17,17 @@ static char SCCSid[] = "$SunId$ SGI"; #define MAXDIST 42 /* maximum distance outside section */ #endif #ifndef NVSAMPS -#define NVSAMPS 4096 /* number of ray samples per view */ +#define NVSAMPS 16384 /* number of ray samples per view */ #endif - +#ifndef MEYERNG +#define MEYERNG 0.1 /* target mean eye range (rel. to grid) */ +#endif +#ifndef MAXTODO #define MAXTODO 3 /* maximum sections to look at */ -#define MAXDRAT 3.0 /* maximum distance ratio */ +#endif +#ifndef MAXDRAT +#define MAXDRAT 3.0 /* maximum distance ratio btwn. cand. sect. */ +#endif #define CBEAMBLK 1024 /* cbeam allocation block size */ @@ -31,6 +37,8 @@ static struct beamcomp { int4 nr; /* number of samples desired */ } *cbeam = NULL; /* current beam list */ +VIEWPOINT cureye; /* current eye position */ + static int ncbeams = 0; /* number of sorted beams in cbeam */ static int xcbeams = 0; /* extra (unregistered) beams past ncbeams */ static int maxcbeam = 0; /* size of cbeam array */ @@ -170,7 +178,7 @@ int n; } -int +static int comptodo(tdl, vw) /* compute holodeck sections in view */ int tdl[MAXTODO+1]; VIEW *vw; @@ -213,12 +221,13 @@ VIEW *vw; } +int addview(hd, vw, hres, vres) /* add view for section */ int hd; VIEW *vw; int hres, vres; { - int sampquant; + int sampquant, samptot = 0; int h, v, shr, svr; GCOORD gc[2]; FVECT rorg, rdir; @@ -242,7 +251,9 @@ int hres, vres; continue; cbeam[getcbeam(hd,hdbindex(hdlist[hd],gc))].nr += sampquant; + samptot += sampquant; } + return(samptot); } @@ -256,23 +267,54 @@ int fresh; else /* else clear sample requests */ for (i = ncbeams+xcbeams; i--; ) cbeam[i].nr = 0; + cureye.rng = 0.; } +int * beam_view(vn, hr, vr) /* add beam view (if advisable) */ VIEW *vn; int hr, vr; { - int todo[MAXTODO+1]; + static int todo[MAXTODO+1]; int n; + double hdgsiz, d; + register HOLO *hp; + register int i; + /* find nearby sections */ + if (!(n = comptodo(todo, vn))) + return(NULL); /* sort our list */ cbeamsort(1); - /* add view to nearby sections */ - if (!(n = comptodo(todo, vn))) - return(0); - while (n--) - addview(todo[n], vn, hr, vr); - return(1); + /* add view to flagged sections */ + for (i = 0; i < n; i++) + if (!addview(todo[i], vn, hr, vr)) { /* whoops! */ + register int j; + n--; /* delete from list */ + for (j = i--; j <= n; j++) + todo[j] = todo[j+1]; + } + if (!n || MEYERNG <= FTINY || vn->type == VT_PAR) + return(todo); + hdgsiz = 0.; /* compute mean grid size */ + for (i = 0; i < n; i++) { + hp = hdlist[todo[i]]; + hdgsiz += 1./3. / VLEN(hp->wg[0]) + + 1./3. / VLEN(hp->wg[1]) + + 1./3. / VLEN(hp->wg[2]) ; + } + hdgsiz /= (double)n; + /* add to current eye position */ + if (cureye.rng <= FTINY) { + VCOPY(cureye.vpt, vn->vp); + cureye.rng = MEYERNG * hdgsiz; + } else if ((d = sqrt(dist2(vn->vp,cureye.vpt))) + MEYERNG*hdgsiz > + cureye.rng) { + for (i = 3; i--; ) + cureye.vpt[i] = 0.5*(cureye.vpt[i] + vn->vp[i]); + cureye.rng = 0.5*(cureye.rng + MEYERNG*hdgsiz + d); + } + return(todo); } @@ -280,8 +322,11 @@ int beam_sync(all) /* update beam list on server */ int all; { + /* set new eye position */ + serv_request(DR_VIEWPOINT, sizeof(VIEWPOINT), (char *)&cureye); /* sort list (put orphans at end) */ cbeamsort(all < 0); + /* send beam request */ if (all) cbeamop(DR_NEWSET, cbeam, ncbeams); else