--- ray/src/hd/rhdisp2.c 1998/11/24 17:05:36 3.26 +++ ray/src/hd/rhdisp2.c 1998/12/22 15:57:20 3.30 @@ -17,7 +17,7 @@ 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) */ @@ -178,7 +178,7 @@ int n; } -int +static int comptodo(tdl, vw) /* compute holodeck sections in view */ int tdl[MAXTODO+1]; VIEW *vw; @@ -221,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; @@ -245,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); } @@ -268,41 +277,53 @@ int fresh; } +int * beam_view(vn, hr, vr) /* add beam view (if advisable) */ VIEW *vn; int hr, vr; { - int todo[MAXTODO+1], n; - double hdgsiz, d; + static int todo[MAXTODO+1]; + int n; + double er, eravg, d; register HOLO *hp; register int i; - /* sort our list */ + /* 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); - for (i = 0; i < n; i++) - addview(todo[i], vn, hr, vr); - if (MEYERNG <= FTINY || vn->type == VT_PAR) - return(1); - hdgsiz = 0.; d = 1./3. / n; /* compute mean grid size */ + eravg = 0.; for (i = 0; i < n; i++) { hp = hdlist[todo[i]]; - hdgsiz += d * ( VLEN(hp->xv[0])/hp->grid[0] + - VLEN(hp->xv[1])/hp->grid[1] + - VLEN(hp->xv[2])/hp->grid[2] ) ; + 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 = MEYERNG * hdgsiz; - } else if ((d = sqrt(dist2(vn->vp,cureye.vpt))) + MEYERNG*hdgsiz > - cureye.rng) { + 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 + MEYERNG*hdgsiz + d); + cureye.rng = 0.5*(cureye.rng + eravg + d); } - return(1); + return(todo); }