--- ray/src/hd/rhdisp3.c 1998/01/06 15:08:50 3.9 +++ ray/src/hd/rhdisp3.c 2018/10/05 19:19:16 3.18 @@ -1,16 +1,12 @@ -/* Copyright (c) 1997 Silicon Graphics, Inc. */ - #ifndef lint -static char SCCSid[] = "$SunId$ SGI"; +static const char RCSid[] = "$Id: rhdisp3.c,v 3.18 2018/10/05 19:19:16 greg Exp $"; #endif - /* * Holodeck beam support for display process */ #include "rholo.h" #include "rhdisp.h" -#include "view.h" struct cellist { GCOORD *cl; @@ -19,24 +15,29 @@ struct cellist { int -npixels(vp, hr, vr, hp, bi) /* compute appropriate number to evaluate */ -register VIEW *vp; +npixels(vp, hr, vr, hp, bi) /* compute appropriate nrays to evaluate */ +VIEW *vp; int hr, vr; HOLO *hp; int bi; { VIEW vrev; GCOORD gc[2]; - FVECT cp[4], ip[4]; - double af, ab; - register int i; + FVECT cp[4], ip[4], pf, pb; + double af, ab, sf2, sb2, dfb2, df2, db2, penalty; + int i; + /* special case */ + if (hr <= 0 | vr <= 0) + return(0); /* compute cell corners in image */ if (!hdbcoord(gc, hp, bi)) error(CONSISTENCY, "bad beam index in npixels"); 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.) { + for (i = 3; i--; ) /* compute front center */ + pf[i] = 0.5*(cp[0][i] + cp[2][i]); + sf2 = 0.25*dist2(cp[0], cp[2]); /* compute half diagonal length */ + for (i = 0; i < 4; i++) { /* compute visible quad */ + if (viewloc(ip[i], vp, cp[i]) <= 0) { af = 0; goto getback; } @@ -48,10 +49,9 @@ int bi; (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; + af *= af >= 0 ? 0.5 : -0.5; getback: - copystruct(&vrev, vp); /* compute reverse view */ + vrev = *vp; /* compute reverse view */ for (i = 0; i < 3; i++) { vrev.vdir[i] = -vp->vdir[i]; vrev.vup[i] = -vp->vup[i]; @@ -59,10 +59,14 @@ getback: vrev.vvec[i] = -vp->vvec[i]; } hdcell(cp, hp, gc); /* find cell on back image */ - for (i = 0; i < 4; i++) { - viewloc(ip[i], &vrev, cp[i]); - if (ip[i][2] < 0.) - return((int)(af + 0.5)); + for (i = 3; i--; ) /* compute rear center */ + pb[i] = 0.5*(cp[0][i] + cp[2][i]); + sb2 = 0.25*dist2(cp[0], cp[2]); /* compute half diagonal length */ + for (i = 0; i < 4; i++) { /* compute visible quad */ + if (viewloc(ip[i], &vrev, cp[i]) <= 0) { + ab = 0; + goto finish; + } ip[i][0] *= (double)hr; /* scale by resolution */ ip[i][1] *= (double)vr; } @@ -71,12 +75,20 @@ getback: (ip[2][0]-ip[0][0])*(ip[1][1]-ip[0][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 (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)); + ab *= ab >= 0 ? 0.5 : -0.5; +finish: /* compute penalty based on dist. sightline - viewpoint */ + df2 = dist2(vp->vp, pf); + db2 = dist2(vp->vp, pb); + dfb2 = dist2(pf, pb); + penalty = dfb2 + df2 - db2; + penalty = df2 - 0.25*penalty*penalty/dfb2; + if (df2 > db2) penalty /= df2 <= dfb2 ? sb2 : sb2*df2/dfb2; + else penalty /= db2 <= dfb2 ? sf2 : sf2*db2/dfb2; + if (penalty < 1.) penalty = 1.; + /* round off smaller non-zero area */ + if (ab <= FTINY || (af > FTINY && af <= ab)) + return((int)(af/penalty + 0.5)); + return((int)(ab/penalty + 0.5)); } @@ -89,7 +101,7 @@ getback: int visit_cells(orig, pyrd, hp, vf, dp) /* visit cells within a pyramid */ FVECT orig, pyrd[4]; /* pyramid ray directions in clockwise order */ -register HOLO *hp; +HOLO *hp; int (*vf)(); char *dp; { @@ -98,7 +110,7 @@ char *dp; FVECT gp, pn[4], lo, ld; double po[4], lbeg, lend, d, t; GCOORD gc, gc2[2]; - register int i; + int i; /* figure out whose side we're on */ hdgrid(gp, hp, orig); for (i = 0; i < 3; i++) { @@ -167,8 +179,8 @@ char *dp; sect_behind(hp, vp) /* check if section is "behind" viewpoint */ -register HOLO *hp; -register VIEW *vp; +HOLO *hp; +VIEW *vp; { FVECT hcent; /* compute holodeck section center */ @@ -185,7 +197,7 @@ FVECT org, dir[4]; HOLO *hp; VIEW *vp; { - register int i; + int i; /* check view type */ if (vp->type == VT_PAR) return(0); @@ -222,9 +234,9 @@ VIEW *vp; int addcell(gcp, cl) /* add a cell to a list */ GCOORD *gcp; -register struct cellist *cl; +struct cellist *cl; { - copystruct(cl->cl+cl->n, gcp); + *(cl->cl+cl->n) = *gcp; cl->n++; return(1); } @@ -232,9 +244,9 @@ register struct cellist *cl; int cellcmp(gcp1, gcp2) /* visit_cells() cell ordering */ -register GCOORD *gcp1, *gcp2; +GCOORD *gcp1, *gcp2; { - register int c; + int c; if ((c = gcp1->w - gcp2->w)) return(c); @@ -247,7 +259,7 @@ register GCOORD *gcp1, *gcp2; GCOORD * getviewcells(np, hp, vp) /* get ordered cell list for section view */ int *np; /* returned number of cells (negative if reversed) */ -register HOLO *hp; +HOLO *hp; VIEW *vp; { FVECT org, dir[4]; @@ -266,9 +278,9 @@ VIEW *vp; if (cl.cl == NULL) goto memerr; cl.n = 0; /* add cells within pyramid */ - visit_cells(org, dir, hp, addcell, &cl); + visit_cells(org, dir, hp, addcell, (char *)&cl); if (!cl.n) { - free((char *)cl.cl); + free((void *)cl.cl); return(NULL); } *np = cl.n * orient; @@ -277,7 +289,7 @@ VIEW *vp; * sorted automatically by visit_cells(), so we don't need this. */ /* optimize memory use */ - cl.cl = (GCOORD *)realloc((char *)cl.cl, cl.n*sizeof(GCOORD)); + cl.cl = (GCOORD *)realloc((void *)cl.cl, cl.n*sizeof(GCOORD)); if (cl.cl == NULL) goto memerr; /* sort the list */ @@ -289,10 +301,12 @@ memerr: } -gridlines(f) /* run through holodeck section grid lines */ -int (*f)(); +void +gridlines( /* run through holodeck section grid lines */ + void (*f)(FVECT wp[2]) +) { - register int hd, w, i; + int hd, w, i; int g0, g1; FVECT wp[2], mov; double d;