--- ray/src/hd/rhdisp3.c 1997/11/21 18:17:37 3.4 +++ ray/src/hd/rhdisp3.c 1997/11/25 16:52:51 3.6 @@ -20,50 +20,63 @@ struct cellist { int npixels(vp, hr, vr, hp, bi) /* compute appropriate number to evaluate */ -VIEW *vp; +register VIEW *vp; int hr, vr; HOLO *hp; int bi; { - static VIEW vdo, vlast; - static HOLO *hplast; + VIEW vrev; GCOORD gc[2]; - FVECT cp[4]; - FVECT ip[4]; - double d; + FVECT cp[4], ip[4]; + double af, ab; register int i; /* compute cell corners in image */ if (!hdbcoord(gc, hp, bi)) error(CONSISTENCY, "bad beam index in npixels"); - /* has holodeck or view changed? */ - if (hp != hplast || bcmp((char *)vp, (char *)&vlast, sizeof(VIEW))) { - copystruct(&vdo, vp); - if (sect_behind(hp, &vdo)) { /* reverse view sense */ - vdo.vdir[0] = -vdo.vdir[0]; - vdo.vdir[1] = -vdo.vdir[1]; - vdo.vdir[2] = -vdo.vdir[2]; - setview(&vdo); + hdcell(cp, hp, gc+1); /* find cell on front image */ + for (i = 0; i < 4; i++) { + viewloc(ip[i], vp, cp[i]); + if (ip[i][2] < 0.) { + af = 0; + goto getback; } - hplast = hp; - copystruct(&vlast, vp); + ip[i][0] *= (double)hr; /* scale by resolution */ + ip[i][1] *= (double)vr; } - hdcell(cp, hp, gc+1); /* find cell on image */ + /* compute front area */ + af = (ip[1][0]-ip[0][0])*(ip[2][1]-ip[0][1]) - + (ip[2][0]-ip[0][0])*(ip[1][1]-ip[0][1]); + af += (ip[2][0]-ip[3][0])*(ip[1][1]-ip[3][1]) - + (ip[1][0]-ip[3][0])*(ip[2][1]-ip[3][1]); + if (af >= 0) af *= 0.5; + else af *= -0.5; +getback: + copystruct(&vrev, vp); /* compute reverse view */ + for (i = 0; i < 3; i++) { + vrev.vdir[i] = -vp->vdir[i]; + vrev.vup[i] = -vp->vup[i]; + vrev.hvec[i] = -vp->hvec[i]; + vrev.vvec[i] = -vp->vvec[i]; + } + hdcell(cp, hp, gc); /* find cell on back image */ for (i = 0; i < 4; i++) { - viewloc(ip[i], &vdo, cp[i]); + viewloc(ip[i], &vrev, cp[i]); if (ip[i][2] < 0.) - return(0); + return((int)(af + 0.5)); ip[i][0] *= (double)hr; /* scale by resolution */ ip[i][1] *= (double)vr; } - /* compute quad area */ - d = (ip[1][0]-ip[0][0])*(ip[2][1]-ip[0][1]) - + /* compute back area */ + ab = (ip[1][0]-ip[0][0])*(ip[2][1]-ip[0][1]) - (ip[2][0]-ip[0][0])*(ip[1][1]-ip[0][1]); - d += (ip[2][0]-ip[3][0])*(ip[1][1]-ip[3][1]) - + ab += (ip[2][0]-ip[3][0])*(ip[1][1]-ip[3][1]) - (ip[1][0]-ip[3][0])*(ip[2][1]-ip[3][1]); - if (d < 0) - d = -d; - /* round off result */ - return((int)(.5*d+.5)); + if (ab >= 0) ab *= 0.5; + else ab *= -0.5; + /* round off smaller area */ + if (af <= ab) + return((int)(af + 0.5)); + return((int)(ab + 0.5)); } @@ -257,4 +270,40 @@ VIEW *vp; return(cl.cl); memerr: error(SYSTEM, "out of memory in getviewcells"); +} + + +gridlines(f) /* run through holodeck section grid lines */ +int (*f)(); +{ + register int hd, w, i; + int g0, g1; + FVECT wp[2]; + double d; + /* do each wall on each section */ + for (hd = 0; hdlist[hd] != NULL; hd++) + for (w = 0; w < 6; w++) { + g0 = ((w>>1)+1)%3; + g1 = ((w>>1)+2)%3; + for (i = hdlist[hd]->grid[g0]; i--; ) { /* g0 lines */ + d = (double)i/hdlist[hd]->grid[g0]; + VSUM(wp[0], hdlist[hd]->orig, + hdlist[hd]->xv[g0], d); + if (w & 1) + VSUM(wp[0], wp[0], + hdlist[hd]->xv[w>>1], 1.); + VSUM(wp[1], wp[0], hdlist[hd]->xv[g1], 1.); + (*f)(wp); + } + for (i = hdlist[hd]->grid[g1]; i--; ) { /* g1 lines */ + d = (double)i/hdlist[hd]->grid[g1]; + VSUM(wp[0], hdlist[hd]->orig, + hdlist[hd]->xv[g1], d); + if (w & 1) + VSUM(wp[0], wp[0], + hdlist[hd]->xv[w>>1], 1.); + VSUM(wp[1], wp[0], hdlist[hd]->xv[g0], 1.); + (*f)(wp); + } + } }