--- ray/src/hd/holo.c 1998/08/31 15:40:13 3.14 +++ ray/src/hd/holo.c 2003/06/26 00:58:10 3.18 @@ -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.18 2003/06/26 00:58:10 schorsch Exp $"; #endif - /* * Routines for converting holodeck coordinates, etc. * @@ -40,11 +37,8 @@ register HOLO *hp; d = DOT(hp->wg[i],hp->xv[i]); 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,40 +54,6 @@ register HOLO *hp; } -HOLO * -hdalloc(hproto) /* allocate and set holodeck section based on grid */ -HDGRID *hproto; -{ - 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; @@ -174,7 +134,7 @@ register FVECT cp[4]; /* returned (may be passed as FV register HOLO *hp; register GCOORD *gc; { - register FLOAT *v; + register RREAL *v; double d; /* compute common component */ VCOPY(cp[0], hp->orig); @@ -303,19 +263,20 @@ FVECT ro, rd; /* normalization of rd affects distance { 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; @@ -345,14 +306,16 @@ FVECT ro, rd; /* normalization of rd affects distance 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]); }