--- ray/src/hd/rholo3.c 1997/12/15 20:44:28 3.13 +++ ray/src/hd/rholo3.c 1997/12/19 09:55:36 3.15 @@ -27,13 +27,40 @@ register PACKHEAD *b0, *b1; } +int +dispbeam(b, hp, bi) /* display a holodeck beam */ +register BEAM *b; +HOLO *hp; +int bi; +{ + static int n = 0; + static PACKHEAD *p = NULL; + + if (b == NULL) + return; + if (b->nrm > n) { /* (re)allocate packet holder */ + n = b->nrm; + if (p == NULL) p = (PACKHEAD *)malloc(packsiz(n)); + else p = (PACKHEAD *)realloc((char *)p, packsiz(n)); + if (p == NULL) + error(SYSTEM, "out of memory in dispbeam"); + } + /* assign packet fields */ + bcopy((char *)hdbray(b), (char *)packra(p), b->nrm*sizeof(RAYVAL)); + p->nr = p->nc = b->nrm; + for (p->hd = 0; hdlist[p->hd] != hp; p->hd++) + if (hdlist[p->hd] == NULL) + error(CONSISTENCY, "unregistered holodeck in dispbeam"); + p->bi = bi; + disp_packet(p); /* display it */ +} + + bundle_set(op, clist, nents) /* bundle set operation */ int op; -PACKHEAD *clist; +register PACKHEAD *clist; int nents; { - BEAM *b; - PACKHEAD *p; register int i, n; switch (op) { @@ -121,29 +148,17 @@ int nents; default: error(CONSISTENCY, "bundle_set called with unknown operation"); } - if (outdev == NULL) - return; - n = 32*RPACKSIZ; /* allocate packet holder */ - p = (PACKHEAD *)malloc(packsiz(n)); - if (p == NULL) - goto memerr; - /* display what we have */ - for (i = 0; i < nents; i++) - if ((b = hdgetbeam(hdlist[clist[i].hd], clist[i].bi)) != NULL) { - if (b->nrm > n) { - n = b->nrm; - p = (PACKHEAD *)realloc((char *)p, packsiz(n)); - if (p == NULL) - goto memerr; - } - bcopy((char *)hdbray(b), (char *)packra(p), - b->nrm*sizeof(RAYVAL)); - p->hd = clist[i].hd; - p->bi = clist[i].bi; - p->nr = p->nc = b->nrm; - disp_packet(p); + if (outdev != NULL) { /* load and display beams we have */ + register HDBEAMI *hb; + + hb = (HDBEAMI *)malloc(nents*sizeof(HDBEAMI)); + for (i = 0; i < nents; i++) { + hb[i].h = hdlist[clist[i].hd]; + hb[i].b = clist[i].bi; } - free((char *)p); /* clean up */ + hdloadbeams(hb, nents, dispbeam); + free((char *)hb); + } if (op == BS_NEW) { done_packets(flush_queue()); /* empty queue, so we can... */ for (i = 0; i < complen; i++) /* ...get number computed */ @@ -176,10 +191,6 @@ int bi; VSUM(edgeA, cp[1], cp[0], -1.0); VSUM(edgeB, cp[3], cp[1], -1.0); fcross(crossp[i], edgeA, edgeB); - VSUM(edgeA, cp[2], cp[3], -1.0); - VSUM(edgeB, cp[0], cp[2], -1.0); - fcross(v, edgeA, edgeB); - VSUM(crossp[i], crossp[i], v, 1.0); /* compute center */ cent[i][0] = 0.5*(cp[0][0] + cp[2][0]); cent[i][1] = 0.5*(cp[0][1] + cp[2][1]); @@ -188,7 +199,7 @@ int bi; /* compute difference vector */ VSUM(diffv, cent[1], cent[0], -1.0); for (i = 0; i < 2; i++) { /* compute volume contributions */ - vol[i] = 0.25*DOT(crossp[i], diffv); + vol[i] = 0.5*DOT(crossp[i], diffv); if (vol[i] < 0.) vol[i] = -vol[i]; } return(vol[0] + vol[1]); /* return total volume */ @@ -216,6 +227,7 @@ init_global() /* initialize global ray computation * for (j = 0; hdlist[j] != NULL; j++) { frac = 512. * hdlist[j]->wg[0] * hdlist[j]->wg[1] * hdlist[j]->wg[2]; + if (frac < 0.) frac = -frac; for (i = nbeams(hdlist[j]); i > 0; i--) { complist[k].hd = j; complist[k].bi = i;