--- ray/src/hd/holo.c 1998/01/06 15:08:50 3.13 +++ ray/src/hd/holo.c 2004/01/01 11:21:55 3.21 @@ -1,9 +1,6 @@ -/* Copyright (c) 1997 Silicon Graphics, Inc. */ - #ifndef lint -static char SCCSid[] = "$SunId$ SGI"; +static const char RCSid[] = "$Id: holo.c,v 3.21 2004/01/01 11:21:55 schorsch Exp $"; #endif - /* * Routines for converting holodeck coordinates, etc. * @@ -20,8 +17,10 @@ int hdwg1[6] = {2,2,0,0,1,1}; static double logstep; -hdcompgrid(hp) /* compute derived grid vector and index */ -register HOLO *hp; +extern void +hdcompgrid( /* compute derived grid vector and index */ + register HOLO *hp +) { double d; register int i, j; @@ -38,13 +37,10 @@ register HOLO *hp; for (i = 0; i < 3; i++) { fcross(hp->wg[i], hp->xv[(i+1)%3], hp->xv[(i+2)%3]); d = DOT(hp->wg[i],hp->xv[i]); - if (d <= FTINY & d >= -FTINY) + if ((d <= FTINY) & (d >= -FTINY)) error(USER, "degenerate holodeck section"); - d = (double)hp->grid[i] / d; + d = hp->grid[i] / d; hp->wg[i][0] *= d; hp->wg[i][1] *= d; hp->wg[i][2] *= d; - hp->wo[i<<1] = DOT(hp->wg[i],hp->orig); - d = DOT(hp->wg[i],hp->xv[i]); - hp->wo[i<<1|1] = hp->wo[i<<1] + d; } /* compute linear depth range */ hp->tlin = VLEN(hp->xv[0]) + VLEN(hp->xv[1]) + VLEN(hp->xv[2]); @@ -60,52 +56,20 @@ register HOLO *hp; } -HOLO * -hdalloc(hproto) /* allocate and set holodeck section based on grid */ -HDGRID *hproto; +extern int +hdbcoord( /* compute beam coordinates from index */ + GCOORD gc[2], /* returned */ + register HOLO *hp, + register int i +) { - HOLO hdhead; - register HOLO *hp; - int n; - /* copy grid to temporary header */ - bcopy((char *)hproto, (char *)&hdhead, sizeof(HDGRID)); - /* compute grid vectors and sizes */ - hdcompgrid(&hdhead); - /* allocate header with directory */ - n = sizeof(HOLO)+nbeams(&hdhead)*sizeof(BEAMI); - if ((hp = (HOLO *)malloc(n)) == NULL) - return(NULL); - /* copy header information */ - copystruct(hp, &hdhead); - /* allocate and clear beam list */ - hp->bl = (BEAM **)malloc((nbeams(hp)+1)*sizeof(BEAM *)+sizeof(BEAM)); - if (hp->bl == NULL) { - free((char *)hp); - return(NULL); - } - bzero((char *)hp->bl, (nbeams(hp)+1)*sizeof(BEAM *)+sizeof(BEAM)); - hp->bl[0] = (BEAM *)(hp->bl+nbeams(hp)+1); /* set blglob(hp) */ - hp->fd = -1; - hp->dirty = 0; - hp->priv = NULL; - /* clear beam directory */ - bzero((char *)hp->bi, (nbeams(hp)+1)*sizeof(BEAMI)); - return(hp); /* all is well */ -} - - -hdbcoord(gc, hp, i) /* compute beam coordinates from index */ -GCOORD gc[2]; /* returned */ -register HOLO *hp; -register int i; -{ register int j, n; int n2, reverse; GCOORD g2[2]; /* check range */ - if (i < 1 | i > nbeams(hp)) + if ((i < 1) | (i > nbeams(hp))) return(0); - if (reverse = i >= hp->wi[5]) + if ( (reverse = i >= hp->wi[5]) ) i -= hp->wi[5] - 1; for (j = 0; j < 5; j++) /* find w0 */ if (hp->wi[j+1] > i) @@ -130,30 +94,31 @@ register int i; gc[1].i[1] = i / hp->grid[hdwg0[gc[1].w]]; gc[1].i[0] = i - gc[1].i[1]*hp->grid[hdwg0[gc[1].w]]; if (reverse) { - copystruct(g2, gc+1); - copystruct(gc+1, gc); - copystruct(gc, g2); + *g2 = *(gc+1); + *(gc+1) = *gc; + *gc = *g2; } return(1); /* we're done */ } -int -hdbindex(hp, gc) /* compute index from beam coordinates */ -register HOLO *hp; -register GCOORD gc[2]; +extern int +hdbindex( /* compute index from beam coordinates */ + register HOLO *hp, + register GCOORD gc[2] +) { GCOORD g2[2]; int reverse; register int i, j; /* check ordering and limits */ - if (reverse = gc[0].w > gc[1].w) { - copystruct(g2, gc+1); - copystruct(g2+1, gc); + if ( (reverse = gc[0].w > gc[1].w) ) { + *g2 = *(gc+1); + *(g2+1) = *gc; gc = g2; } else if (gc[0].w == gc[1].w) return(0); - if (gc[0].w < 0 | gc[1].w > 5) + if ((gc[0].w < 0) | (gc[1].w > 5)) return(0); i = 0; /* compute index */ for (j = gc[0].w+1; j < gc[1].w; j++) @@ -169,12 +134,14 @@ register GCOORD gc[2]; } -hdcell(cp, hp, gc) /* compute cell coordinates */ -register FVECT cp[4]; /* returned (may be passed as FVECT cp[2][2]) */ -register HOLO *hp; -register GCOORD *gc; +extern void +hdcell( /* compute cell coordinates */ + register FVECT cp[4], /* returned (may be passed as FVECT cp[2][2]) */ + register HOLO *hp, + register GCOORD *gc +) { - register FLOAT *v; + register RREAL *v; double d; /* compute common component */ VCOPY(cp[0], hp->orig); @@ -201,10 +168,12 @@ register GCOORD *gc; } -hdlseg(lseg, hp, gc) /* compute line segment for beam */ -register int lseg[2][3]; -register HOLO *hp; -GCOORD gc[2]; +extern int +hdlseg( /* compute line segment for beam */ + register int lseg[2][3], + register HOLO *hp, + GCOORD gc[2] +) { register int k; @@ -217,10 +186,11 @@ GCOORD gc[2]; } -unsigned -hdcode(hp, d) /* compute depth code for d */ -HOLO *hp; -double d; +extern unsigned int +hdcode( /* compute depth code for d */ + HOLO *hp, + double d +) { double tl = hp->tlin; register long c; @@ -236,26 +206,28 @@ double d; } -hdgrid(gp, hp, wp) /* compute grid coordinates */ -FVECT gp; /* returned */ -register HOLO *hp; -FVECT wp; +extern void +hdgrid( /* compute grid coordinates */ + FVECT gp, /* returned */ + register HOLO *hp, + FVECT wp +) { FVECT vt; - vt[0] = wp[0] - hp->orig[0]; - vt[1] = wp[1] - hp->orig[1]; - vt[2] = wp[2] - hp->orig[2]; + VSUB(vt, wp, hp->orig); gp[0] = DOT(vt, hp->wg[0]); gp[1] = DOT(vt, hp->wg[1]); gp[2] = DOT(vt, hp->wg[2]); } -hdworld(wp, hp, gp) /* compute world coordinates */ -register FVECT wp; -register HOLO *hp; -FVECT gp; +extern void +hdworld( /* compute world coordinates */ + register FVECT wp, + register HOLO *hp, + FVECT gp +) { register double d; @@ -270,12 +242,14 @@ FVECT gp; } -double -hdray(ro, rd, hp, gc, r) /* compute ray within a beam */ -FVECT ro, rd; /* returned */ -HOLO *hp; -GCOORD gc[2]; -BYTE r[2][2]; +extern double +hdray( /* compute ray within a beam */ + FVECT ro, + FVECT rd, /* returned */ + HOLO *hp, + GCOORD gc[2], + BYTE r[2][2] +) { FVECT cp[4], p[2]; register int i, j; @@ -290,36 +264,37 @@ BYTE r[2][2]; d0*cp[1][j] + d1*cp[2][j]; } VCOPY(ro, p[0]); /* assign ray origin and direction */ - rd[0] = p[1][0] - p[0][0]; - rd[1] = p[1][1] - p[0][1]; - rd[2] = p[1][2] - p[0][2]; + VSUB(rd, p[1], p[0]); return(normalize(rd)); /* return maximum inside distance */ } -double -hdinter(gc, r, ed, hp, ro, rd) /* compute ray intersection with section */ -register GCOORD gc[2]; /* returned */ -BYTE r[2][2]; /* returned (optional) */ -double *ed; /* returned (optional) */ -register HOLO *hp; -FVECT ro, rd; /* normalization of rd affects distances */ +extern double +hdinter( /* compute ray intersection with section */ + register GCOORD gc[2], /* returned */ + BYTE r[2][2], /* returned (optional) */ + double *ed, /* returned (optional) */ + register HOLO *hp, + FVECT ro, + FVECT rd /* normalization of rd affects distances */ +) { FVECT p[2], vt; double d, t0, t1, d0, d1; - register FLOAT *v; + register RREAL *v; register int i; /* first, intersect walls */ gc[0].w = gc[1].w = -1; t0 = -FHUGE; t1 = FHUGE; + VSUB(vt, ro, hp->orig); for (i = 0; i < 3; i++) { /* for each wall pair */ d = -DOT(rd, hp->wg[i]); /* plane distance */ if (d <= FTINY && d >= -FTINY) /* check for parallel */ continue; - d1 = DOT(ro, hp->wg[i]); /* ray distances */ - d0 = (d1 - hp->wo[i<<1]) / d; - d1 = (d1 - hp->wo[i<<1|1]) / d; - if (d0 < d1) { /* check against best */ + d1 = DOT(vt, hp->wg[i]); /* ray distances */ + d0 = d1 / d; + d1 = (d1 - hp->grid[i]) / d; + if (d < 0) { /* check against best */ if (d0 > t0) { t0 = d0; gc[0].w = i<<1; @@ -339,28 +314,26 @@ FVECT ro, rd; /* normalization of rd affects distance } } } - if (gc[0].w < 0 | gc[1].w < 0) /* paranoid check */ + if ((gc[0].w < 0) | (gc[1].w < 0)) /* paranoid check */ return(FHUGE); /* compute intersections */ - for (i = 0; i < 3; i++) { - p[0][i] = ro[i] + rd[i]*t0; - p[1][i] = ro[i] + rd[i]*t1; - } + VSUM(p[0], ro, rd, t0); + VSUM(p[1], ro, rd, t1); /* now, compute grid coordinates */ for (i = 0; i < 2; i++) { - vt[0] = p[i][0] - hp->orig[0]; - vt[1] = p[i][1] - hp->orig[1]; - vt[2] = p[i][2] - hp->orig[2]; + VSUB(vt, p[i], hp->orig); v = hp->wg[hdwg0[gc[i].w]]; d = DOT(vt, v); - if (d < 0. || (gc[i].i[0] = d) >= hp->grid[hdwg0[gc[i].w]]) + if (d < 0 || d >= hp->grid[hdwg0[gc[i].w]]) return(FHUGE); /* outside wall */ + gc[i].i[0] = d; if (r != NULL) r[i][0] = 256. * (d - gc[i].i[0]); v = hp->wg[hdwg1[gc[i].w]]; d = DOT(vt, v); - if (d < 0. || (gc[i].i[1] = d) >= hp->grid[hdwg1[gc[i].w]]) + if (d < 0 || d >= hp->grid[hdwg1[gc[i].w]]) return(FHUGE); /* outside wall */ + gc[i].i[1] = d; if (r != NULL) r[i][1] = 256. * (d - gc[i].i[1]); }