12 |
|
#include "rhdisp.h" |
13 |
|
#include "rhdriver.h" |
14 |
|
|
15 |
< |
extern int *getviewcells(); |
15 |
> |
extern GCOORD *getviewcells(); |
16 |
|
|
17 |
|
typedef struct { |
18 |
|
int hd; /* holodeck section number (-1 if inactive) */ |
39 |
|
struct cellact { |
40 |
|
short vi; /* voxel index */ |
41 |
|
short add; /* zero means delete */ |
42 |
+ |
short rev; /* reverse ray direction? */ |
43 |
|
}; /* action for cell */ |
44 |
|
|
45 |
|
struct beamact { |
275 |
|
GCOORD gc[2]; |
276 |
|
int bi, i; |
277 |
|
/* compute beam index */ |
278 |
< |
copystruct(gc, gcp); |
279 |
< |
copystruct(gc+1, &bp->gc); |
278 |
> |
if (bp->ca.rev) { |
279 |
> |
copystruct(gc, &bp->gc); |
280 |
> |
copystruct(gc+1, gcp); |
281 |
> |
} else { |
282 |
> |
copystruct(gc, gcp); |
283 |
> |
copystruct(gc+1, &bp->gc); |
284 |
> |
} |
285 |
|
if ((bi = hdbindex(hdlist[voxel[bp->ca.vi].hd], gc)) <= 0) |
286 |
|
error(CONSISTENCY, "bad grid coordinate in dobeam"); |
287 |
|
if (bp->ca.add) { /* add it in */ |
341 |
|
struct cellact *cap; |
342 |
|
VIEW *vp; |
343 |
|
{ |
344 |
+ |
int orient; |
345 |
|
FVECT org, dir[4]; |
346 |
|
/* compute view pyramid */ |
347 |
< |
if (vp->type == VT_PAR) goto viewerr; |
348 |
< |
if (viewray(org, dir[0], vp, 0., 0.) < -FTINY) goto viewerr; |
349 |
< |
if (viewray(org, dir[1], vp, 0., 1.) < -FTINY) goto viewerr; |
350 |
< |
if (viewray(org, dir[2], vp, 1., 1.) < -FTINY) goto viewerr; |
344 |
< |
if (viewray(org, dir[3], vp, 1., 0.) < -FTINY) goto viewerr; |
347 |
> |
orient = viewpyramid(org, dir, hdlist[voxel[cap->vi].hd], vp); |
348 |
> |
if (!orient) |
349 |
> |
error(INTERNAL, "unusable view in doview"); |
350 |
> |
cap->rev = orient < 0; |
351 |
|
/* visit cells within pyramid */ |
352 |
|
return(visit_cells(org, dir, hdlist[voxel[cap->vi].hd], docell, cap)); |
347 |
– |
viewerr: |
348 |
– |
error(INTERNAL, "unusable view in doview"); |
353 |
|
} |
354 |
|
|
355 |
|
|
358 |
|
VIEW *vold, *vnew; |
359 |
|
{ |
360 |
|
int netchange = 0; |
361 |
< |
int *ocl, *ncl; |
358 |
< |
struct cellact ca; |
361 |
> |
struct cellact oca, nca; |
362 |
|
int ocnt, ncnt; |
363 |
|
int c; |
364 |
|
register GCOORD *ogcp, *ngcp; |
365 |
|
/* get old and new cell lists */ |
366 |
< |
ocl = getviewcells(hdlist[voxel[voxi].hd], vold); |
367 |
< |
ncl = getviewcells(hdlist[voxel[voxi].hd], vnew); |
368 |
< |
if (ocl != NULL) { |
369 |
< |
ocnt = *ocl; ogcp = (GCOORD *)(ocl+1); |
370 |
< |
} else { |
371 |
< |
ocnt = 0; ogcp = NULL; |
372 |
< |
} |
373 |
< |
if (ncl != NULL) { |
374 |
< |
ncnt = *ncl; ngcp = (GCOORD *)(ncl+1); |
375 |
< |
} else { |
376 |
< |
ncnt = 0; ngcp = NULL; |
377 |
< |
} |
378 |
< |
ca.vi = voxi; /* add and delete cells */ |
379 |
< |
while (ocnt > 0 & ncnt > 0) |
380 |
< |
if ((c = cellcmp(ogcp, ngcp)) > 0) { |
381 |
< |
ca.add = 1; /* new cell */ |
382 |
< |
netchange += docell(ngcp++, &ca); |
383 |
< |
ncnt--; |
384 |
< |
} else if (c < 0) { |
385 |
< |
ca.add = 0; /* obsolete cell */ |
386 |
< |
netchange -= docell(ogcp++, &ca); |
387 |
< |
ocnt--; |
385 |
< |
} else { |
386 |
< |
ogcp++; ocnt--; /* unchanged cell */ |
387 |
< |
ngcp++; ncnt--; |
388 |
< |
} |
366 |
> |
ogcp = getviewcells(&ocnt, hdlist[voxel[voxi].hd], vold); |
367 |
> |
ngcp = getviewcells(&ncnt, hdlist[voxel[voxi].hd], vnew); |
368 |
> |
/* set up actions */ |
369 |
> |
oca.vi = nca.vi = voxi; |
370 |
> |
oca.rev = nca.rev = 0; |
371 |
> |
oca.add = 0; nca.add = 1; |
372 |
> |
if ((oca.rev = ocnt < 0)) |
373 |
> |
ocnt = -ocnt; |
374 |
> |
if ((nca.rev = ncnt < 0)) |
375 |
> |
ncnt = -ncnt; |
376 |
> |
if (nca.rev == oca.rev) /* add and delete cells in order */ |
377 |
> |
while (ocnt > 0 & ncnt > 0) |
378 |
> |
if ((c = cellcmp(ogcp, ngcp)) > 0) { /* new cell */ |
379 |
> |
netchange += docell(ngcp++, &nca); |
380 |
> |
ncnt--; |
381 |
> |
} else if (c < 0) { /* old cell */ |
382 |
> |
netchange -= docell(ogcp++, &oca); |
383 |
> |
ocnt--; |
384 |
> |
} else { /* same cell */ |
385 |
> |
ogcp++; ocnt--; |
386 |
> |
ngcp++; ncnt--; |
387 |
> |
} |
388 |
|
/* take care of list tails */ |
389 |
< |
for (ca.add = 1; ncnt > 0; ncnt--) |
390 |
< |
netchange += docell(ngcp++, &ca); |
391 |
< |
for (ca.add = 0; ocnt > 0; ocnt--) |
392 |
< |
netchange -= docell(ogcp++, &ca); |
389 |
> |
for ( ; ncnt > 0; ncnt--) |
390 |
> |
netchange += docell(ngcp++, &nca); |
391 |
> |
for ( ; ocnt > 0; ocnt--) |
392 |
> |
netchange -= docell(ogcp++, &oca); |
393 |
|
/* clean up */ |
394 |
< |
if (ocl != NULL) free((char *)ocl); |
395 |
< |
if (ncl != NULL) free((char *)ncl); |
394 |
> |
if (ogcp != NULL) free((char *)ogcp); |
395 |
> |
if (ngcp != NULL) free((char *)ngcp); |
396 |
|
return(netchange); |
397 |
|
} |
398 |
|
|