| 17 |
|
#define MAXDIST 42 /* maximum distance outside section */ |
| 18 |
|
#endif |
| 19 |
|
#ifndef NVSAMPS |
| 20 |
< |
#define NVSAMPS 4096 /* number of ray samples per view */ |
| 20 |
> |
#define NVSAMPS 16384 /* number of ray samples per view */ |
| 21 |
|
#endif |
| 22 |
< |
|
| 22 |
> |
#ifndef MEYERNG |
| 23 |
> |
#define MEYERNG 0.2 /* target mean eye range (rel. to grid) */ |
| 24 |
> |
#endif |
| 25 |
> |
#ifndef MAXTODO |
| 26 |
|
#define MAXTODO 3 /* maximum sections to look at */ |
| 27 |
< |
#define MAXDRAT 3.0 /* maximum distance ratio */ |
| 27 |
> |
#endif |
| 28 |
> |
#ifndef MAXDRAT |
| 29 |
> |
#define MAXDRAT 3.0 /* maximum distance ratio btwn. cand. sect. */ |
| 30 |
> |
#endif |
| 31 |
|
|
| 32 |
|
#define CBEAMBLK 1024 /* cbeam allocation block size */ |
| 33 |
|
|
| 37 |
|
int4 nr; /* number of samples desired */ |
| 38 |
|
} *cbeam = NULL; /* current beam list */ |
| 39 |
|
|
| 40 |
+ |
VIEWPOINT cureye; /* current eye position */ |
| 41 |
+ |
|
| 42 |
|
static int ncbeams = 0; /* number of sorted beams in cbeam */ |
| 43 |
|
static int xcbeams = 0; /* extra (unregistered) beams past ncbeams */ |
| 44 |
|
static int maxcbeam = 0; /* size of cbeam array */ |
| 178 |
|
} |
| 179 |
|
|
| 180 |
|
|
| 181 |
< |
int |
| 181 |
> |
static int |
| 182 |
|
comptodo(tdl, vw) /* compute holodeck sections in view */ |
| 183 |
|
int tdl[MAXTODO+1]; |
| 184 |
|
VIEW *vw; |
| 221 |
|
} |
| 222 |
|
|
| 223 |
|
|
| 224 |
< |
addview(hd, vw, hres, vres) /* add view for section */ |
| 224 |
> |
int |
| 225 |
> |
addview(hd, vw, rad, hres, vres) /* add view for section */ |
| 226 |
|
int hd; |
| 227 |
|
VIEW *vw; |
| 228 |
+ |
double rad; |
| 229 |
|
int hres, vres; |
| 230 |
|
{ |
| 231 |
< |
int sampquant; |
| 231 |
> |
int sampquant, samptot = 0; |
| 232 |
|
int h, v, shr, svr; |
| 233 |
|
GCOORD gc[2]; |
| 234 |
|
FVECT rorg, rdir; |
| 247 |
|
if (viewray(rorg, rdir, vw, (v+frandom())/svr, |
| 248 |
|
(h+frandom())/shr) < -FTINY) |
| 249 |
|
continue; |
| 250 |
+ |
if (rad > FTINY) { |
| 251 |
+ |
rorg[0] += (1.-2.*frandom())*rad; |
| 252 |
+ |
rorg[1] += (1.-2.*frandom())*rad; |
| 253 |
+ |
rorg[2] += (1.-2.*frandom())*rad; |
| 254 |
+ |
} |
| 255 |
|
if (hdinter(gc, NULL, NULL, hdlist[hd], rorg, rdir) |
| 256 |
< |
>= FHUGE) |
| 256 |
> |
>= 0.99*FHUGE) |
| 257 |
|
continue; |
| 258 |
|
cbeam[getcbeam(hd,hdbindex(hdlist[hd],gc))].nr += |
| 259 |
|
sampquant; |
| 260 |
+ |
samptot += sampquant; |
| 261 |
|
} |
| 262 |
+ |
return(samptot); |
| 263 |
|
} |
| 264 |
|
|
| 265 |
|
|
| 273 |
|
else /* else clear sample requests */ |
| 274 |
|
for (i = ncbeams+xcbeams; i--; ) |
| 275 |
|
cbeam[i].nr = 0; |
| 276 |
+ |
cureye.rng = 0.; |
| 277 |
|
} |
| 278 |
|
|
| 279 |
|
|
| 280 |
+ |
int * |
| 281 |
|
beam_view(vn, hr, vr) /* add beam view (if advisable) */ |
| 282 |
|
VIEW *vn; |
| 283 |
|
int hr, vr; |
| 284 |
|
{ |
| 285 |
< |
int todo[MAXTODO+1]; |
| 285 |
> |
static int todo[MAXTODO+1]; |
| 286 |
|
int n; |
| 287 |
< |
/* sort our list */ |
| 287 |
> |
double er, eravg, d; |
| 288 |
> |
register HOLO *hp; |
| 289 |
> |
register int i; |
| 290 |
> |
/* find nearby sections */ |
| 291 |
> |
if (!(n = comptodo(todo, vn))) |
| 292 |
> |
return(NULL); |
| 293 |
> |
/* sort current beam list */ |
| 294 |
|
cbeamsort(1); |
| 295 |
|
/* add view to nearby sections */ |
| 296 |
< |
if (!(n = comptodo(todo, vn))) |
| 297 |
< |
return(0); |
| 298 |
< |
while (n--) |
| 299 |
< |
addview(todo[n], vn, hr, vr); |
| 300 |
< |
return(1); |
| 296 |
> |
eravg = 0.; |
| 297 |
> |
for (i = 0; i < n; i++) { |
| 298 |
> |
hp = hdlist[todo[i]]; |
| 299 |
> |
if (MEYERNG > FTINY) |
| 300 |
> |
er = MEYERNG/3. / VLEN(hp->wg[0]) + |
| 301 |
> |
MEYERNG/3. / VLEN(hp->wg[1]) + |
| 302 |
> |
MEYERNG/3. / VLEN(hp->wg[2]) ; |
| 303 |
> |
else |
| 304 |
> |
er = 0.; |
| 305 |
> |
if (!addview(todo[i], vn, 0.25*er, hr, vr)) { |
| 306 |
> |
register int j; /* whoops! */ |
| 307 |
> |
n--; /* delete from list */ |
| 308 |
> |
for (j = i--; j <= n; j++) |
| 309 |
> |
todo[j] = todo[j+1]; |
| 310 |
> |
} else |
| 311 |
> |
eravg += er; |
| 312 |
> |
} |
| 313 |
> |
if (eravg <= FTINY) |
| 314 |
> |
return(todo); |
| 315 |
> |
/* compute average eye range */ |
| 316 |
> |
eravg /= (double)n; |
| 317 |
> |
/* add to current eye position */ |
| 318 |
> |
if (cureye.rng <= FTINY) { |
| 319 |
> |
VCOPY(cureye.vpt, vn->vp); |
| 320 |
> |
cureye.rng = eravg; |
| 321 |
> |
} else if ((d = sqrt(dist2(vn->vp,cureye.vpt))) + eravg > cureye.rng) { |
| 322 |
> |
for (i = 3; i--; ) |
| 323 |
> |
cureye.vpt[i] = 0.5*(cureye.vpt[i] + vn->vp[i]); |
| 324 |
> |
cureye.rng = 0.5*(cureye.rng + eravg + d); |
| 325 |
> |
} |
| 326 |
> |
return(todo); |
| 327 |
|
} |
| 328 |
|
|
| 329 |
|
|
| 331 |
|
beam_sync(all) /* update beam list on server */ |
| 332 |
|
int all; |
| 333 |
|
{ |
| 334 |
+ |
/* set new eye position */ |
| 335 |
+ |
serv_request(DR_VIEWPOINT, sizeof(VIEWPOINT), (char *)&cureye); |
| 336 |
|
/* sort list (put orphans at end) */ |
| 337 |
|
cbeamsort(all < 0); |
| 338 |
+ |
/* send beam request */ |
| 339 |
|
if (all) |
| 340 |
|
cbeamop(DR_NEWSET, cbeam, ncbeams); |
| 341 |
|
else |