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 |
+ |
#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) */ |
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 |
|
{ |
229 |
– |
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; |
266 |
< |
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 |
|
|
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[((gcp->w>>1)+1)%3] = gcp->i[0] + .5; |
326 |
> |
cgp[((gcp->w>>1)+2)%3] = 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->wn[axmax], vc) < 0.) |
354 |
+ |
d = -d; /* reverse vertex ordering */ |
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 |
|
|
393 |
|
struct cellact oca, nca; |
394 |
|
int ocnt, ncnt; |
395 |
|
int c; |
396 |
+ |
GCOORD *ogcl, *ngcl; |
397 |
|
register GCOORD *ogcp, *ngcp; |
398 |
|
/* get old and new cell lists */ |
399 |
< |
ogcp = getviewcells(&ocnt, hdlist[voxel[voxi].hd], vold); |
400 |
< |
ngcp = getviewcells(&ncnt, hdlist[voxel[voxi].hd], vnew); |
399 |
> |
ogcp = ogcl = getviewcells(&ocnt, hdlist[voxel[voxi].hd], vold); |
400 |
> |
ngcp = ngcl = getviewcells(&ncnt, hdlist[voxel[voxi].hd], vnew); |
401 |
|
/* set up actions */ |
402 |
|
oca.vi = nca.vi = voxi; |
370 |
– |
oca.rev = nca.rev = 0; |
403 |
|
oca.add = 0; nca.add = 1; |
404 |
|
if ((oca.rev = ocnt < 0)) |
405 |
|
ocnt = -ocnt; |
423 |
|
for ( ; ocnt > 0; ocnt--) |
424 |
|
netchange -= docell(ogcp++, &oca); |
425 |
|
/* clean up */ |
426 |
< |
if (ogcp != NULL) free((char *)ogcp); |
427 |
< |
if (ngcp != NULL) free((char *)ngcp); |
426 |
> |
if (ogcl != NULL) free((char *)ogcl); |
427 |
> |
if (ngcl != NULL) free((char *)ngcl); |
428 |
|
return(netchange); |
429 |
|
} |
430 |
|
|
431 |
|
|
432 |
+ |
int |
433 |
|
beam_sync() /* synchronize beams on server */ |
434 |
|
{ |
435 |
|
cbeamop(DR_NEWSET, cbeam, ncbeams, &odev.v, odev.hres, odev.vres); |
436 |
+ |
return(ncbeams); |
437 |
|
} |
438 |
|
|
439 |
|
|
440 |
< |
beam_view(vo, vn) /* change beam view */ |
441 |
< |
VIEW *vo, *vn; |
440 |
> |
beam_view(vn) /* change beam view (if advisable) */ |
441 |
> |
VIEW *vn; |
442 |
|
{ |
443 |
|
struct cellact ca; |
444 |
|
VOXL vlnew[8]; |
445 |
|
int n, comn; |
446 |
|
|
447 |
< |
if (!vn->type) { /* clear our beam list */ |
447 |
> |
if (vn == NULL || !vn->type) { /* clear our beam list */ |
448 |
|
set_voxels(vlnew, 0); |
449 |
|
cbeamop(DR_DELSET, cbeam, ncbeams, NULL, 0, 0); |
450 |
|
ncbeams = 0; |
451 |
< |
return; |
451 |
> |
dvw.type = 0; |
452 |
> |
return(1); |
453 |
|
} |
454 |
|
/* find our new voxels */ |
455 |
|
n = get_voxels(vlnew, vn->vp); |
456 |
+ |
if (dvw.type && !n) { |
457 |
+ |
copystruct(vn, &dvw); /* cancel move */ |
458 |
+ |
return(0); |
459 |
+ |
} |
460 |
|
/* set the new voxels */ |
461 |
|
comn = set_voxels(vlnew, n); |
462 |
< |
if (!vo->type) |
462 |
> |
if (!dvw.type) |
463 |
|
comn = 0; |
464 |
|
ca.add = 1; /* update our beam list */ |
465 |
|
for (ca.vi = n; ca.vi--; ) |
466 |
|
if (comn & 1<<ca.vi) /* change which cells we see */ |
467 |
< |
mvview(ca.vi, vo, vn); |
467 |
> |
mvview(ca.vi, &dvw, vn); |
468 |
|
else /* else add all new cells */ |
469 |
|
doview(&ca, vn); |
470 |
|
/* inform server of new beams */ |
474 |
|
/* tell server to delete orphans */ |
475 |
|
cbeamop(DR_DELSET, cbeam+ncbeams, xcbeams, NULL, 0, 0); |
476 |
|
xcbeams = 0; /* truncate our list */ |
477 |
+ |
copystruct(&dvw, vn); /* record new view */ |
478 |
+ |
return(1); |
479 |
|
} |