1 |
< |
/* Copyright (c) 1997 Silicon Graphics, Inc. */ |
1 |
> |
/* Copyright (c) 1998 Silicon Graphics, Inc. */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ SGI"; |
12 |
|
#include "rhdisp.h" |
13 |
|
#include "rhdriver.h" |
14 |
|
|
15 |
< |
extern int *getviewcells(); |
15 |
> |
#ifndef MAXDIST |
16 |
> |
#define MAXDIST 42 /* maximum distance outside section */ |
17 |
> |
#endif |
18 |
|
|
19 |
+ |
extern GCOORD *getviewcells(); |
20 |
+ |
|
21 |
+ |
static VIEW dvw; /* current view corresponding to beam list */ |
22 |
+ |
|
23 |
|
typedef struct { |
24 |
|
int hd; /* holodeck section number (-1 if inactive) */ |
25 |
|
int i[3]; /* voxel index (may be outside section) */ |
45 |
|
struct cellact { |
46 |
|
short vi; /* voxel index */ |
47 |
|
short add; /* zero means delete */ |
48 |
+ |
short rev; /* reverse ray direction? */ |
49 |
|
}; /* action for cell */ |
50 |
|
|
51 |
|
struct beamact { |
94 |
|
|
95 |
|
if (!cb1->wants) /* put orphans at the end, unsorted */ |
96 |
|
return(cb2->wants); |
97 |
+ |
if (!cb2->wants) |
98 |
+ |
return(-1); |
99 |
|
if ((c = cb1->bi - cb2->bi)) /* sort on beam index first */ |
100 |
|
return(c); |
101 |
|
return(cb1->hd - cb2->hd); /* use hd to resolve matches */ |
184 |
|
pa[i].bi = bl[i].bi; |
185 |
|
pa[i].nr = v==NULL ? 0 : |
186 |
|
npixels(v, hr, vr, hdlist[bl[i].hd], bl[i].bi); |
187 |
+ |
pa[i].nc = 0; |
188 |
|
} |
189 |
|
serv_request(op, n*sizeof(PACKHEAD), (char *)pa); |
190 |
|
free((char *)pa); |
235 |
|
VOXL vl[8]; |
236 |
|
FVECT vp; |
237 |
|
{ |
228 |
– |
static int lastn = 0, lastd = -1; |
238 |
|
int n = 0; |
239 |
|
FVECT gp; |
240 |
|
double d; |
265 |
|
n++; |
266 |
|
} |
267 |
|
} |
268 |
< |
/* warn of dangerous moves */ |
269 |
< |
if (n < lastn && bestd >= lastd) |
270 |
< |
error(WARNING, "moving outside holodeck section"); |
271 |
< |
else if (n > lastn && bestd <= lastd) |
272 |
< |
error(WARNING, "moving inside holodeck section"); |
273 |
< |
lastd = bestd; |
265 |
< |
return(lastn = n); |
268 |
> |
/* check for really stupid move */ |
269 |
> |
if (bestd > MAXDIST) { |
270 |
> |
error(COMMAND, "move past outer limits"); |
271 |
> |
return(0); |
272 |
> |
} |
273 |
> |
return(n); |
274 |
|
} |
275 |
|
|
276 |
|
|
282 |
|
GCOORD gc[2]; |
283 |
|
int bi, i; |
284 |
|
/* compute beam index */ |
285 |
< |
copystruct(gc, gcp); |
286 |
< |
copystruct(gc+1, &bp->gc); |
285 |
> |
if (bp->ca.rev) { |
286 |
> |
copystruct(gc, &bp->gc); |
287 |
> |
copystruct(gc+1, gcp); |
288 |
> |
} else { |
289 |
> |
copystruct(gc, gcp); |
290 |
> |
copystruct(gc+1, &bp->gc); |
291 |
> |
} |
292 |
|
if ((bi = hdbindex(hdlist[voxel[bp->ca.vi].hd], gc)) <= 0) |
293 |
|
error(CONSISTENCY, "bad grid coordinate in dobeam"); |
294 |
|
if (bp->ca.add) { /* add it in */ |
312 |
|
GCOORD *gcp; |
313 |
|
register struct cellact *cap; |
314 |
|
{ |
315 |
+ |
register HOLO *hp = hdlist[voxel[cap->vi].hd]; |
316 |
|
FVECT org, dir[4]; |
317 |
< |
FVECT gp, cv[4], vc; |
317 |
> |
FVECT vgp, cgp, vc; |
318 |
> |
FVECT v1, v2; |
319 |
|
struct beamact bo; |
320 |
+ |
int axmax, j; |
321 |
+ |
double d, avmax; |
322 |
|
register int i; |
323 |
< |
/* compute cell vertices */ |
324 |
< |
hdcell(cv, hdlist[voxel[cap->vi].hd], gcp); |
325 |
< |
/* compute cell and voxel centers */ |
326 |
< |
for (i = 0; i < 3; i++) { |
327 |
< |
org[i] = 0.5*(cv[0][i] + cv[2][i]); |
328 |
< |
gp[i] = voxel[cap->vi].i[i] + 0.5; |
329 |
< |
} |
330 |
< |
hdworld(vc, hdlist[voxel[cap->vi].hd], gp); |
331 |
< |
/* compute voxel pyramid using vector trick */ |
332 |
< |
for (i = 0; i < 3; i++) { |
333 |
< |
dir[0][i] = vc[i] - cv[0][i]; /* to 3 */ |
334 |
< |
dir[2][i] = vc[i] - cv[3][i]; /* to 0 */ |
335 |
< |
if (gcp->w & 1) { /* watch vertex order! */ |
336 |
< |
dir[1][i] = vc[i] - cv[2][i]; /* to 1 */ |
337 |
< |
dir[3][i] = vc[i] - cv[1][i]; /* to 2 */ |
338 |
< |
} else { |
339 |
< |
dir[1][i] = vc[i] - cv[1][i]; /* to 2 */ |
340 |
< |
dir[3][i] = vc[i] - cv[2][i]; /* to 1 */ |
323 |
> |
/* compute cell center */ |
324 |
> |
cgp[gcp->w>>1] = gcp->w&1 ? hp->grid[gcp->w>>1] : 0 ; |
325 |
> |
cgp[hdwg0[gcp->w]] = gcp->i[0] + .5; |
326 |
> |
cgp[hdwg1[gcp->w]] = gcp->i[1] + .5; |
327 |
> |
hdworld(org, hp, cgp); |
328 |
> |
/* compute direction to voxel center */ |
329 |
> |
for (i = 3; i--; ) |
330 |
> |
vgp[i] = voxel[cap->vi].i[i] + .5; |
331 |
> |
hdworld(vc, hp, vgp); |
332 |
> |
for (i = 3; i--; ) |
333 |
> |
vc[i] -= org[i]; |
334 |
> |
/* compute maximum area axis */ |
335 |
> |
axmax = -1; avmax = 0; |
336 |
> |
for (i = 3; i--; ) { |
337 |
> |
d = vgp[i] - cgp[i]; |
338 |
> |
if (d < 0.) d = -d; |
339 |
> |
if (d > avmax) { |
340 |
> |
avmax = d; |
341 |
> |
axmax = i; |
342 |
|
} |
343 |
|
} |
344 |
+ |
#ifdef DEBUG |
345 |
+ |
if (axmax < 0.) |
346 |
+ |
error(CONSISTENCY, "botched axis computation in docell"); |
347 |
+ |
#endif |
348 |
+ |
/* compute offset vectors */ |
349 |
+ |
d = 0.5/hp->grid[j=(axmax+1)%3]; |
350 |
+ |
for (i = 3; i--; ) |
351 |
+ |
v1[i] = hp->xv[j][i] * d; |
352 |
+ |
d = 0.5/hp->grid[j=(axmax+2)%3]; |
353 |
+ |
if (DOT(hp->wg[axmax], vc) < 0.) |
354 |
+ |
d = -d; /* reverse vertex order */ |
355 |
+ |
for (i = 3; i--; ) |
356 |
+ |
v2[i] = hp->xv[j][i] * d; |
357 |
+ |
/* compute voxel pyramid */ |
358 |
+ |
for (i = 3; i--; ) { |
359 |
+ |
dir[0][i] = vc[i] - v1[i] - v2[i]; |
360 |
+ |
dir[1][i] = vc[i] + v1[i] - v2[i]; |
361 |
+ |
dir[2][i] = vc[i] + v1[i] + v2[i]; |
362 |
+ |
dir[3][i] = vc[i] - v1[i] + v2[i]; |
363 |
+ |
} |
364 |
|
/* visit beams for opposite cells */ |
365 |
|
copystruct(&bo.ca, cap); |
366 |
|
copystruct(&bo.gc, gcp); |
367 |
< |
return(visit_cells(org, dir, hdlist[voxel[cap->vi].hd], dobeam, &bo)); |
367 |
> |
return(visit_cells(org, dir, hp, dobeam, &bo)); |
368 |
|
} |
369 |
|
|
370 |
|
|
373 |
|
struct cellact *cap; |
374 |
|
VIEW *vp; |
375 |
|
{ |
376 |
+ |
int orient; |
377 |
|
FVECT org, dir[4]; |
378 |
|
/* compute view pyramid */ |
379 |
< |
if (vp->type == VT_PAR) goto viewerr; |
380 |
< |
if (viewray(org, dir[0], vp, 0., 0.) < -FTINY) goto viewerr; |
381 |
< |
if (viewray(org, dir[1], vp, 0., 1.) < -FTINY) goto viewerr; |
382 |
< |
if (viewray(org, dir[2], vp, 1., 1.) < -FTINY) goto viewerr; |
344 |
< |
if (viewray(org, dir[3], vp, 1., 0.) < -FTINY) goto viewerr; |
379 |
> |
orient = viewpyramid(org, dir, hdlist[voxel[cap->vi].hd], vp); |
380 |
> |
if (!orient) |
381 |
> |
error(INTERNAL, "unusable view in doview"); |
382 |
> |
cap->rev = orient < 0; |
383 |
|
/* visit cells within pyramid */ |
384 |
|
return(visit_cells(org, dir, hdlist[voxel[cap->vi].hd], docell, cap)); |
347 |
– |
viewerr: |
348 |
– |
error(INTERNAL, "unusable view in doview"); |
385 |
|
} |
386 |
|
|
387 |
|
|
390 |
|
VIEW *vold, *vnew; |
391 |
|
{ |
392 |
|
int netchange = 0; |
393 |
< |
int *ocl, *ncl; |
358 |
< |
struct cellact ca; |
393 |
> |
struct cellact oca, nca; |
394 |
|
int ocnt, ncnt; |
395 |
< |
int c; |
395 |
> |
int nmatch = 0; |
396 |
> |
GCOORD *ogcl, *ngcl; |
397 |
> |
register int c; |
398 |
|
register GCOORD *ogcp, *ngcp; |
399 |
|
/* get old and new cell lists */ |
400 |
< |
ocl = getviewcells(hdlist[voxel[voxi].hd], vold); |
401 |
< |
ncl = getviewcells(hdlist[voxel[voxi].hd], vnew); |
402 |
< |
if (ocl != NULL) { |
403 |
< |
ocnt = *ocl; ogcp = (GCOORD *)(ocl+1); |
404 |
< |
} else { |
405 |
< |
ocnt = 0; ogcp = NULL; |
400 |
> |
ogcp = ogcl = getviewcells(&ocnt, hdlist[voxel[voxi].hd], vold); |
401 |
> |
ngcp = ngcl = getviewcells(&ncnt, hdlist[voxel[voxi].hd], vnew); |
402 |
> |
/* set up actions */ |
403 |
> |
oca.vi = nca.vi = voxi; |
404 |
> |
oca.add = 0; nca.add = 1; |
405 |
> |
if ((oca.rev = ocnt < 0)) |
406 |
> |
ocnt = -ocnt; |
407 |
> |
if ((nca.rev = ncnt < 0)) |
408 |
> |
ncnt = -ncnt; |
409 |
> |
if (oca.rev == nca.rev) { /* count matches */ |
410 |
> |
int oc = ocnt, nc = ncnt; |
411 |
> |
while (oc > 0 & nc > 0) { |
412 |
> |
c = cellcmp(ogcp, ngcp); |
413 |
> |
if (c >= 0) { ngcp++; nc--; } |
414 |
> |
if (c <= 0) { ogcp++; oc--; } |
415 |
> |
nmatch += c==0; |
416 |
> |
} |
417 |
> |
ogcp = ogcl; ngcp = ngcl; |
418 |
|
} |
419 |
< |
if (ncl != NULL) { |
420 |
< |
ncnt = *ncl; ngcp = (GCOORD *)(ncl+1); |
421 |
< |
} else { |
422 |
< |
ncnt = 0; ngcp = NULL; |
419 |
> |
if (nmatch < ocnt>>1) { /* faster to just delete old cells? */ |
420 |
> |
for (c = ncbeams; c--; ) |
421 |
> |
if (cbeam[c].wants & 1<<voxi) { |
422 |
> |
cbeam[c].wants &= ~(1<<voxi); |
423 |
> |
netchange--; |
424 |
> |
} |
425 |
> |
free((char *)ogcl); |
426 |
> |
ogcl = NULL; ocnt = 0; |
427 |
|
} |
428 |
< |
ca.vi = voxi; /* add and delete cells */ |
428 |
> |
/* add and delete cells in order */ |
429 |
|
while (ocnt > 0 & ncnt > 0) |
430 |
< |
if ((c = cellcmp(ogcp, ngcp)) > 0) { |
431 |
< |
ca.add = 1; /* new cell */ |
379 |
< |
netchange += docell(ngcp++, &ca); |
430 |
> |
if ((c = cellcmp(ogcp, ngcp)) > 0) { /* new cell */ |
431 |
> |
netchange += docell(ngcp++, &nca); |
432 |
|
ncnt--; |
433 |
< |
} else if (c < 0) { |
434 |
< |
ca.add = 0; /* obsolete cell */ |
383 |
< |
netchange -= docell(ogcp++, &ca); |
433 |
> |
} else if (c < 0) { /* old cell */ |
434 |
> |
netchange -= docell(ogcp++, &oca); |
435 |
|
ocnt--; |
436 |
< |
} else { |
437 |
< |
ogcp++; ocnt--; /* unchanged cell */ |
436 |
> |
} else { /* same cell */ |
437 |
> |
ogcp++; ocnt--; |
438 |
|
ngcp++; ncnt--; |
439 |
|
} |
440 |
|
/* take care of list tails */ |
441 |
< |
for (ca.add = 1; ncnt > 0; ncnt--) |
442 |
< |
netchange += docell(ngcp++, &ca); |
443 |
< |
for (ca.add = 0; ocnt > 0; ocnt--) |
444 |
< |
netchange -= docell(ogcp++, &ca); |
441 |
> |
for ( ; ncnt > 0; ncnt--) |
442 |
> |
netchange += docell(ngcp++, &nca); |
443 |
> |
for ( ; ocnt > 0; ocnt--) |
444 |
> |
netchange -= docell(ogcp++, &oca); |
445 |
|
/* clean up */ |
446 |
< |
if (ocl != NULL) free((char *)ocl); |
447 |
< |
if (ncl != NULL) free((char *)ncl); |
446 |
> |
if (ogcl != NULL) free((char *)ogcl); |
447 |
> |
if (ngcl != NULL) free((char *)ngcl); |
448 |
|
return(netchange); |
449 |
|
} |
450 |
|
|
451 |
|
|
452 |
+ |
int |
453 |
|
beam_sync() /* synchronize beams on server */ |
454 |
|
{ |
455 |
|
cbeamop(DR_NEWSET, cbeam, ncbeams, &odev.v, odev.hres, odev.vres); |
456 |
+ |
return(ncbeams); |
457 |
|
} |
458 |
|
|
459 |
|
|
460 |
< |
beam_view(vo, vn) /* change beam view */ |
461 |
< |
VIEW *vo, *vn; |
460 |
> |
beam_view(vn) /* change beam view (if advisable) */ |
461 |
> |
VIEW *vn; |
462 |
|
{ |
463 |
|
struct cellact ca; |
464 |
|
VOXL vlnew[8]; |
465 |
|
int n, comn; |
466 |
|
|
467 |
< |
if (!vn->type) { /* clear our beam list */ |
467 |
> |
if (vn == NULL || !vn->type) { /* clear our beam list */ |
468 |
|
set_voxels(vlnew, 0); |
469 |
|
cbeamop(DR_DELSET, cbeam, ncbeams, NULL, 0, 0); |
470 |
|
ncbeams = 0; |
471 |
< |
return; |
471 |
> |
dvw.type = 0; |
472 |
> |
return(1); |
473 |
|
} |
474 |
|
/* find our new voxels */ |
475 |
|
n = get_voxels(vlnew, vn->vp); |
476 |
+ |
if (dvw.type && !n) { |
477 |
+ |
copystruct(vn, &dvw); /* cancel move */ |
478 |
+ |
return(0); |
479 |
+ |
} |
480 |
|
/* set the new voxels */ |
481 |
|
comn = set_voxels(vlnew, n); |
482 |
< |
if (!vo->type) |
482 |
> |
if (!dvw.type) |
483 |
|
comn = 0; |
484 |
|
ca.add = 1; /* update our beam list */ |
485 |
|
for (ca.vi = n; ca.vi--; ) |
486 |
|
if (comn & 1<<ca.vi) /* change which cells we see */ |
487 |
< |
mvview(ca.vi, vo, vn); |
487 |
> |
mvview(ca.vi, &dvw, vn); |
488 |
|
else /* else add all new cells */ |
489 |
|
doview(&ca, vn); |
490 |
|
/* inform server of new beams */ |
494 |
|
/* tell server to delete orphans */ |
495 |
|
cbeamop(DR_DELSET, cbeam+ncbeams, xcbeams, NULL, 0, 0); |
496 |
|
xcbeams = 0; /* truncate our list */ |
497 |
+ |
copystruct(&dvw, vn); /* record new view */ |
498 |
+ |
return(1); |
499 |
|
} |