| 1 |
– |
/* Copyright (c) 1998 Silicon Graphics, Inc. */ |
| 2 |
– |
|
| 1 |
|
#ifndef lint |
| 2 |
< |
static char SCCSid[] = "$SunId$ SGI"; |
| 2 |
> |
static const char RCSid[] = "$Id$"; |
| 3 |
|
#endif |
| 6 |
– |
|
| 4 |
|
/* |
| 5 |
|
* Routines for converting holodeck coordinates, etc. |
| 6 |
|
* |
| 17 |
|
static double logstep; |
| 18 |
|
|
| 19 |
|
|
| 20 |
< |
hdcompgrid(hp) /* compute derived grid vector and index */ |
| 21 |
< |
register HOLO *hp; |
| 20 |
> |
extern void |
| 21 |
> |
hdcompgrid( /* compute derived grid vector and index */ |
| 22 |
> |
register HOLO *hp |
| 23 |
> |
) |
| 24 |
|
{ |
| 25 |
|
double d; |
| 26 |
|
register int i, j; |
| 37 |
|
for (i = 0; i < 3; i++) { |
| 38 |
|
fcross(hp->wg[i], hp->xv[(i+1)%3], hp->xv[(i+2)%3]); |
| 39 |
|
d = DOT(hp->wg[i],hp->xv[i]); |
| 40 |
< |
if (d <= FTINY & d >= -FTINY) |
| 40 |
> |
if ((d <= FTINY) & (d >= -FTINY)) |
| 41 |
|
error(USER, "degenerate holodeck section"); |
| 42 |
|
d = hp->grid[i] / d; |
| 43 |
|
hp->wg[i][0] *= d; hp->wg[i][1] *= d; hp->wg[i][2] *= d; |
| 56 |
|
} |
| 57 |
|
|
| 58 |
|
|
| 59 |
< |
HOLO * |
| 60 |
< |
hdalloc(hproto) /* allocate and set holodeck section based on grid */ |
| 61 |
< |
HDGRID *hproto; |
| 59 |
> |
extern int |
| 60 |
> |
hdbcoord( /* compute beam coordinates from index */ |
| 61 |
> |
GCOORD gc[2], /* returned */ |
| 62 |
> |
register HOLO *hp, |
| 63 |
> |
register int i |
| 64 |
> |
) |
| 65 |
|
{ |
| 64 |
– |
HOLO hdhead; |
| 65 |
– |
register HOLO *hp; |
| 66 |
– |
int n; |
| 67 |
– |
/* copy grid to temporary header */ |
| 68 |
– |
bcopy((char *)hproto, (char *)&hdhead, sizeof(HDGRID)); |
| 69 |
– |
/* compute grid vectors and sizes */ |
| 70 |
– |
hdcompgrid(&hdhead); |
| 71 |
– |
/* allocate header with directory */ |
| 72 |
– |
n = sizeof(HOLO)+nbeams(&hdhead)*sizeof(BEAMI); |
| 73 |
– |
if ((hp = (HOLO *)malloc(n)) == NULL) |
| 74 |
– |
return(NULL); |
| 75 |
– |
/* copy header information */ |
| 76 |
– |
copystruct(hp, &hdhead); |
| 77 |
– |
/* allocate and clear beam list */ |
| 78 |
– |
hp->bl = (BEAM **)malloc((nbeams(hp)+1)*sizeof(BEAM *)+sizeof(BEAM)); |
| 79 |
– |
if (hp->bl == NULL) { |
| 80 |
– |
free((char *)hp); |
| 81 |
– |
return(NULL); |
| 82 |
– |
} |
| 83 |
– |
bzero((char *)hp->bl, (nbeams(hp)+1)*sizeof(BEAM *)+sizeof(BEAM)); |
| 84 |
– |
hp->bl[0] = (BEAM *)(hp->bl+nbeams(hp)+1); /* set blglob(hp) */ |
| 85 |
– |
hp->fd = -1; |
| 86 |
– |
hp->dirty = 0; |
| 87 |
– |
hp->priv = NULL; |
| 88 |
– |
/* clear beam directory */ |
| 89 |
– |
bzero((char *)hp->bi, (nbeams(hp)+1)*sizeof(BEAMI)); |
| 90 |
– |
return(hp); /* all is well */ |
| 91 |
– |
} |
| 92 |
– |
|
| 93 |
– |
|
| 94 |
– |
hdbcoord(gc, hp, i) /* compute beam coordinates from index */ |
| 95 |
– |
GCOORD gc[2]; /* returned */ |
| 96 |
– |
register HOLO *hp; |
| 97 |
– |
register int i; |
| 98 |
– |
{ |
| 66 |
|
register int j, n; |
| 67 |
|
int n2, reverse; |
| 68 |
|
GCOORD g2[2]; |
| 69 |
|
/* check range */ |
| 70 |
< |
if (i < 1 | i > nbeams(hp)) |
| 70 |
> |
if ((i < 1) | (i > nbeams(hp))) |
| 71 |
|
return(0); |
| 72 |
< |
if (reverse = i >= hp->wi[5]) |
| 72 |
> |
if ( (reverse = i >= hp->wi[5]) ) |
| 73 |
|
i -= hp->wi[5] - 1; |
| 74 |
|
for (j = 0; j < 5; j++) /* find w0 */ |
| 75 |
|
if (hp->wi[j+1] > i) |
| 94 |
|
gc[1].i[1] = i / hp->grid[hdwg0[gc[1].w]]; |
| 95 |
|
gc[1].i[0] = i - gc[1].i[1]*hp->grid[hdwg0[gc[1].w]]; |
| 96 |
|
if (reverse) { |
| 97 |
< |
copystruct(g2, gc+1); |
| 98 |
< |
copystruct(gc+1, gc); |
| 99 |
< |
copystruct(gc, g2); |
| 97 |
> |
*g2 = *(gc+1); |
| 98 |
> |
*(gc+1) = *gc; |
| 99 |
> |
*gc = *g2; |
| 100 |
|
} |
| 101 |
|
return(1); /* we're done */ |
| 102 |
|
} |
| 103 |
|
|
| 104 |
|
|
| 105 |
< |
int |
| 106 |
< |
hdbindex(hp, gc) /* compute index from beam coordinates */ |
| 107 |
< |
register HOLO *hp; |
| 108 |
< |
register GCOORD gc[2]; |
| 105 |
> |
extern int |
| 106 |
> |
hdbindex( /* compute index from beam coordinates */ |
| 107 |
> |
register HOLO *hp, |
| 108 |
> |
register GCOORD gc[2] |
| 109 |
> |
) |
| 110 |
|
{ |
| 111 |
|
GCOORD g2[2]; |
| 112 |
|
int reverse; |
| 113 |
|
register int i, j; |
| 114 |
|
/* check ordering and limits */ |
| 115 |
< |
if (reverse = gc[0].w > gc[1].w) { |
| 116 |
< |
copystruct(g2, gc+1); |
| 117 |
< |
copystruct(g2+1, gc); |
| 115 |
> |
if ( (reverse = gc[0].w > gc[1].w) ) { |
| 116 |
> |
*g2 = *(gc+1); |
| 117 |
> |
*(g2+1) = *gc; |
| 118 |
|
gc = g2; |
| 119 |
|
} else if (gc[0].w == gc[1].w) |
| 120 |
|
return(0); |
| 121 |
< |
if (gc[0].w < 0 | gc[1].w > 5) |
| 121 |
> |
if ((gc[0].w < 0) | (gc[1].w > 5)) |
| 122 |
|
return(0); |
| 123 |
|
i = 0; /* compute index */ |
| 124 |
|
for (j = gc[0].w+1; j < gc[1].w; j++) |
| 134 |
|
} |
| 135 |
|
|
| 136 |
|
|
| 137 |
< |
hdcell(cp, hp, gc) /* compute cell coordinates */ |
| 138 |
< |
register FVECT cp[4]; /* returned (may be passed as FVECT cp[2][2]) */ |
| 139 |
< |
register HOLO *hp; |
| 140 |
< |
register GCOORD *gc; |
| 137 |
> |
extern void |
| 138 |
> |
hdcell( /* compute cell coordinates */ |
| 139 |
> |
register FVECT cp[4], /* returned (may be passed as FVECT cp[2][2]) */ |
| 140 |
> |
register HOLO *hp, |
| 141 |
> |
register GCOORD *gc |
| 142 |
> |
) |
| 143 |
|
{ |
| 144 |
< |
register FLOAT *v; |
| 144 |
> |
register RREAL *v; |
| 145 |
|
double d; |
| 146 |
|
/* compute common component */ |
| 147 |
|
VCOPY(cp[0], hp->orig); |
| 168 |
|
} |
| 169 |
|
|
| 170 |
|
|
| 171 |
< |
hdlseg(lseg, hp, gc) /* compute line segment for beam */ |
| 172 |
< |
register int lseg[2][3]; |
| 173 |
< |
register HOLO *hp; |
| 174 |
< |
GCOORD gc[2]; |
| 171 |
> |
extern int |
| 172 |
> |
hdlseg( /* compute line segment for beam */ |
| 173 |
> |
register int lseg[2][3], |
| 174 |
> |
register HOLO *hp, |
| 175 |
> |
GCOORD gc[2] |
| 176 |
> |
) |
| 177 |
|
{ |
| 178 |
|
register int k; |
| 179 |
|
|
| 186 |
|
} |
| 187 |
|
|
| 188 |
|
|
| 189 |
< |
unsigned |
| 190 |
< |
hdcode(hp, d) /* compute depth code for d */ |
| 191 |
< |
HOLO *hp; |
| 192 |
< |
double d; |
| 189 |
> |
extern unsigned int |
| 190 |
> |
hdcode( /* compute depth code for d */ |
| 191 |
> |
HOLO *hp, |
| 192 |
> |
double d |
| 193 |
> |
) |
| 194 |
|
{ |
| 195 |
|
double tl = hp->tlin; |
| 196 |
|
register long c; |
| 206 |
|
} |
| 207 |
|
|
| 208 |
|
|
| 209 |
< |
hdgrid(gp, hp, wp) /* compute grid coordinates */ |
| 210 |
< |
FVECT gp; /* returned */ |
| 211 |
< |
register HOLO *hp; |
| 212 |
< |
FVECT wp; |
| 209 |
> |
extern void |
| 210 |
> |
hdgrid( /* compute grid coordinates */ |
| 211 |
> |
FVECT gp, /* returned */ |
| 212 |
> |
register HOLO *hp, |
| 213 |
> |
FVECT wp |
| 214 |
> |
) |
| 215 |
|
{ |
| 216 |
|
FVECT vt; |
| 217 |
|
|
| 222 |
|
} |
| 223 |
|
|
| 224 |
|
|
| 225 |
< |
hdworld(wp, hp, gp) /* compute world coordinates */ |
| 226 |
< |
register FVECT wp; |
| 227 |
< |
register HOLO *hp; |
| 228 |
< |
FVECT gp; |
| 225 |
> |
extern void |
| 226 |
> |
hdworld( /* compute world coordinates */ |
| 227 |
> |
register FVECT wp, |
| 228 |
> |
register HOLO *hp, |
| 229 |
> |
FVECT gp |
| 230 |
> |
) |
| 231 |
|
{ |
| 232 |
|
register double d; |
| 233 |
|
|
| 242 |
|
} |
| 243 |
|
|
| 244 |
|
|
| 245 |
< |
double |
| 246 |
< |
hdray(ro, rd, hp, gc, r) /* compute ray within a beam */ |
| 247 |
< |
FVECT ro, rd; /* returned */ |
| 248 |
< |
HOLO *hp; |
| 249 |
< |
GCOORD gc[2]; |
| 250 |
< |
BYTE r[2][2]; |
| 245 |
> |
extern double |
| 246 |
> |
hdray( /* compute ray within a beam */ |
| 247 |
> |
FVECT ro, |
| 248 |
> |
FVECT rd, /* returned */ |
| 249 |
> |
HOLO *hp, |
| 250 |
> |
GCOORD gc[2], |
| 251 |
> |
BYTE r[2][2] |
| 252 |
> |
) |
| 253 |
|
{ |
| 254 |
|
FVECT cp[4], p[2]; |
| 255 |
|
register int i, j; |
| 269 |
|
} |
| 270 |
|
|
| 271 |
|
|
| 272 |
< |
double |
| 273 |
< |
hdinter(gc, r, ed, hp, ro, rd) /* compute ray intersection with section */ |
| 274 |
< |
register GCOORD gc[2]; /* returned */ |
| 275 |
< |
BYTE r[2][2]; /* returned (optional) */ |
| 276 |
< |
double *ed; /* returned (optional) */ |
| 277 |
< |
register HOLO *hp; |
| 278 |
< |
FVECT ro, rd; /* normalization of rd affects distances */ |
| 272 |
> |
extern double |
| 273 |
> |
hdinter( /* compute ray intersection with section */ |
| 274 |
> |
register GCOORD gc[2], /* returned */ |
| 275 |
> |
BYTE r[2][2], /* returned (optional) */ |
| 276 |
> |
double *ed, /* returned (optional) */ |
| 277 |
> |
register HOLO *hp, |
| 278 |
> |
FVECT ro, |
| 279 |
> |
FVECT rd /* normalization of rd affects distances */ |
| 280 |
> |
) |
| 281 |
|
{ |
| 282 |
|
FVECT p[2], vt; |
| 283 |
|
double d, t0, t1, d0, d1; |
| 284 |
< |
register FLOAT *v; |
| 284 |
> |
register RREAL *v; |
| 285 |
|
register int i; |
| 286 |
|
/* first, intersect walls */ |
| 287 |
|
gc[0].w = gc[1].w = -1; |
| 314 |
|
} |
| 315 |
|
} |
| 316 |
|
} |
| 317 |
< |
if (gc[0].w < 0 | gc[1].w < 0) /* paranoid check */ |
| 317 |
> |
if ((gc[0].w < 0) | (gc[1].w < 0)) /* paranoid check */ |
| 318 |
|
return(FHUGE); |
| 319 |
|
/* compute intersections */ |
| 320 |
|
VSUM(p[0], ro, rd, t0); |