--- ray/src/hd/rhdisp2.c 1998/11/24 12:01:17 3.25 +++ ray/src/hd/rhdisp2.c 1998/12/22 15:57:20 3.30 @@ -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.2 /* 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,14 @@ VIEW *vw; } -addview(hd, vw, hres, vres) /* add view for section */ +int +addview(hd, vw, rad, hres, vres) /* add view for section */ int hd; VIEW *vw; +double rad; int hres, vres; { - int sampquant; + int sampquant, samptot = 0; int h, v, shr, svr; GCOORD gc[2]; FVECT rorg, rdir; @@ -237,12 +247,19 @@ int hres, vres; if (viewray(rorg, rdir, vw, (v+frandom())/svr, (h+frandom())/shr) < -FTINY) continue; + if (rad > FTINY) { + rorg[0] += (1.-2.*frandom())*rad; + rorg[1] += (1.-2.*frandom())*rad; + rorg[2] += (1.-2.*frandom())*rad; + } if (hdinter(gc, NULL, NULL, hdlist[hd], rorg, rdir) - >= FHUGE) + >= 0.99*FHUGE) continue; cbeam[getcbeam(hd,hdbindex(hdlist[hd],gc))].nr += sampquant; + samptot += sampquant; } + return(samptot); } @@ -256,23 +273,57 @@ 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; - /* sort our list */ + double er, eravg, d; + register HOLO *hp; + register int i; + /* find nearby sections */ + if (!(n = comptodo(todo, vn))) + return(NULL); + /* sort current beam 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); + eravg = 0.; + for (i = 0; i < n; i++) { + hp = hdlist[todo[i]]; + if (MEYERNG > FTINY) + er = MEYERNG/3. / VLEN(hp->wg[0]) + + MEYERNG/3. / VLEN(hp->wg[1]) + + MEYERNG/3. / VLEN(hp->wg[2]) ; + else + er = 0.; + if (!addview(todo[i], vn, 0.25*er, hr, vr)) { + register int j; /* whoops! */ + n--; /* delete from list */ + for (j = i--; j <= n; j++) + todo[j] = todo[j+1]; + } else + eravg += er; + } + if (eravg <= FTINY) + return(todo); + /* compute average eye range */ + eravg /= (double)n; + /* add to current eye position */ + if (cureye.rng <= FTINY) { + VCOPY(cureye.vpt, vn->vp); + cureye.rng = eravg; + } else if ((d = sqrt(dist2(vn->vp,cureye.vpt))) + eravg > cureye.rng) { + for (i = 3; i--; ) + cureye.vpt[i] = 0.5*(cureye.vpt[i] + vn->vp[i]); + cureye.rng = 0.5*(cureye.rng + eravg + d); + } + return(todo); } @@ -280,8 +331,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