1 |
< |
/* Copyright (c) 1997 Silicon Graphics, Inc. */ |
1 |
> |
/* Copyright (c) 1998 Silicon Graphics, Inc. */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ SGI"; |
14 |
|
|
15 |
|
float hd_depthmap[DCINF-DCLIN]; |
16 |
|
|
17 |
+ |
int hdwg0[6] = {1,1,2,2,0,0}; |
18 |
+ |
int hdwg1[6] = {2,2,0,0,1,1}; |
19 |
+ |
|
20 |
|
static double logstep; |
21 |
|
|
19 |
– |
static int wg0[6] = {1,1,2,2,0,0}; |
20 |
– |
static int wg1[6] = {2,2,0,0,1,1}; |
22 |
|
|
22 |
– |
|
23 |
|
hdcompgrid(hp) /* compute derived grid vector and index */ |
24 |
|
register HOLO *hp; |
25 |
|
{ |
36 |
|
} |
37 |
|
/* compute grid coordinate vectors */ |
38 |
|
for (i = 0; i < 3; i++) { |
39 |
< |
fcross(hp->wn[i], hp->xv[(i+1)%3], hp->xv[(i+2)%3]); |
40 |
< |
if (normalize(hp->wn[i]) == 0.) |
39 |
> |
fcross(hp->wg[i], hp->xv[(i+1)%3], hp->xv[(i+2)%3]); |
40 |
> |
d = DOT(hp->wg[i],hp->xv[i]); |
41 |
> |
if (d <= FTINY & d >= -FTINY) |
42 |
|
error(USER, "degenerate holodeck section"); |
43 |
< |
hp->wo[i<<1] = DOT(hp->wn[i],hp->orig); |
44 |
< |
d = DOT(hp->wn[i],hp->xv[i]); |
44 |
< |
hp->wo[i<<1|1] = hp->wo[i<<1] + d; |
45 |
< |
hp->wg[i] = (double)hp->grid[i] / d; |
43 |
> |
d = hp->grid[i] / d; |
44 |
> |
hp->wg[i][0] *= d; hp->wg[i][1] *= d; hp->wg[i][2] *= d; |
45 |
|
} |
46 |
|
/* compute linear depth range */ |
47 |
|
hp->tlin = VLEN(hp->xv[0]) + VLEN(hp->xv[1]) + VLEN(hp->xv[2]); |
50 |
|
for (i = 1; i < 6; i++) { |
51 |
|
hp->wi[i] = 0; |
52 |
|
for (j = i; j < 6; j++) |
53 |
< |
hp->wi[i] += hp->grid[wg0[j]] * hp->grid[wg1[j]]; |
54 |
< |
hp->wi[i] *= hp->grid[wg0[i-1]] * hp->grid[wg1[i-1]]; |
53 |
> |
hp->wi[i] += hp->grid[hdwg0[j]] * hp->grid[hdwg1[j]]; |
54 |
> |
hp->wi[i] *= hp->grid[hdwg0[i-1]] * hp->grid[hdwg1[i-1]]; |
55 |
|
hp->wi[i] += hp->wi[i-1]; |
56 |
|
} |
57 |
|
} |
58 |
|
|
59 |
|
|
61 |
– |
HOLO * |
62 |
– |
hdalloc(hproto) /* allocate and set holodeck section based on grid */ |
63 |
– |
HDGRID *hproto; |
64 |
– |
{ |
65 |
– |
HOLO hdhead; |
66 |
– |
register HOLO *hp; |
67 |
– |
int n; |
68 |
– |
/* copy grid to temporary header */ |
69 |
– |
bcopy((char *)hproto, (char *)&hdhead, sizeof(HDGRID)); |
70 |
– |
/* compute grid vectors and sizes */ |
71 |
– |
hdcompgrid(&hdhead); |
72 |
– |
/* allocate header with directory */ |
73 |
– |
n = sizeof(HOLO)+nbeams(&hdhead)*sizeof(BEAMI); |
74 |
– |
if ((hp = (HOLO *)malloc(n)) == NULL) |
75 |
– |
return(NULL); |
76 |
– |
/* copy header information */ |
77 |
– |
copystruct(hp, &hdhead); |
78 |
– |
/* allocate and clear beam list */ |
79 |
– |
hp->bl = (BEAM **)malloc((nbeams(hp)+1)*sizeof(BEAM *)+sizeof(BEAM)); |
80 |
– |
if (hp->bl == NULL) { |
81 |
– |
free((char *)hp); |
82 |
– |
return(NULL); |
83 |
– |
} |
84 |
– |
bzero((char *)hp->bl, (nbeams(hp)+1)*sizeof(BEAM *)+sizeof(BEAM)); |
85 |
– |
hp->bl[0] = (BEAM *)(hp->bl+nbeams(hp)+1); /* set blglob(hp) */ |
86 |
– |
hp->fd = -1; |
87 |
– |
hp->dirty = 0; |
88 |
– |
hp->priv = NULL; |
89 |
– |
/* clear beam directory */ |
90 |
– |
bzero((char *)hp->bi, (nbeams(hp)+1)*sizeof(BEAMI)); |
91 |
– |
return(hp); /* all is well */ |
92 |
– |
} |
93 |
– |
|
94 |
– |
|
60 |
|
hdbcoord(gc, hp, i) /* compute beam coordinates from index */ |
61 |
|
GCOORD gc[2]; /* returned */ |
62 |
|
register HOLO *hp; |
75 |
|
break; |
76 |
|
i -= hp->wi[gc[0].w=j]; |
77 |
|
/* find w1 */ |
78 |
< |
n2 = hp->grid[wg0[j]] * hp->grid[wg1[j]]; |
78 |
> |
n2 = hp->grid[hdwg0[j]] * hp->grid[hdwg1[j]]; |
79 |
|
while (++j < 5) { |
80 |
< |
n = n2 * hp->grid[wg0[j]] * hp->grid[wg1[j]]; |
80 |
> |
n = n2 * hp->grid[hdwg0[j]] * hp->grid[hdwg1[j]]; |
81 |
|
if (n > i) |
82 |
|
break; |
83 |
|
i -= n; |
84 |
|
} |
85 |
|
gc[1].w = j; |
86 |
|
/* find position on w0 */ |
87 |
< |
n2 = hp->grid[wg0[j]] * hp->grid[wg1[j]]; |
87 |
> |
n2 = hp->grid[hdwg0[j]] * hp->grid[hdwg1[j]]; |
88 |
|
n = i / n2; |
89 |
< |
gc[0].i[1] = n / hp->grid[wg0[gc[0].w]]; |
90 |
< |
gc[0].i[0] = n - gc[0].i[1]*hp->grid[wg0[gc[0].w]]; |
89 |
> |
gc[0].i[1] = n / hp->grid[hdwg0[gc[0].w]]; |
90 |
> |
gc[0].i[0] = n - gc[0].i[1]*hp->grid[hdwg0[gc[0].w]]; |
91 |
|
i -= n*n2; |
92 |
|
/* find position on w1 */ |
93 |
< |
gc[1].i[1] = i / hp->grid[wg0[gc[1].w]]; |
94 |
< |
gc[1].i[0] = i - gc[1].i[1]*hp->grid[wg0[gc[1].w]]; |
93 |
> |
gc[1].i[1] = i / hp->grid[hdwg0[gc[1].w]]; |
94 |
> |
gc[1].i[0] = i - gc[1].i[1]*hp->grid[hdwg0[gc[1].w]]; |
95 |
|
if (reverse) { |
96 |
|
copystruct(g2, gc+1); |
97 |
|
copystruct(gc+1, gc); |
120 |
|
return(0); |
121 |
|
i = 0; /* compute index */ |
122 |
|
for (j = gc[0].w+1; j < gc[1].w; j++) |
123 |
< |
i += hp->grid[wg0[j]] * hp->grid[wg1[j]]; |
124 |
< |
i *= hp->grid[wg0[gc[0].w]] * hp->grid[wg1[gc[0].w]]; |
123 |
> |
i += hp->grid[hdwg0[j]] * hp->grid[hdwg1[j]]; |
124 |
> |
i *= hp->grid[hdwg0[gc[0].w]] * hp->grid[hdwg1[gc[0].w]]; |
125 |
|
i += hp->wi[gc[0].w]; |
126 |
< |
i += (hp->grid[wg0[gc[0].w]]*gc[0].i[1] + gc[0].i[0]) * |
127 |
< |
hp->grid[wg0[gc[1].w]] * hp->grid[wg1[gc[1].w]] ; |
128 |
< |
i += hp->grid[wg0[gc[1].w]]*gc[1].i[1] + gc[1].i[0]; |
126 |
> |
i += (hp->grid[hdwg0[gc[0].w]]*gc[0].i[1] + gc[0].i[0]) * |
127 |
> |
hp->grid[hdwg0[gc[1].w]] * hp->grid[hdwg1[gc[1].w]] ; |
128 |
> |
i += hp->grid[hdwg0[gc[1].w]]*gc[1].i[1] + gc[1].i[0]; |
129 |
|
if (reverse) |
130 |
|
i += hp->wi[5] - 1; |
131 |
|
return(i); |
145 |
|
v = hp->xv[gc->w>>1]; |
146 |
|
cp[0][0] += v[0]; cp[0][1] += v[1]; cp[0][2] += v[2]; |
147 |
|
} |
148 |
< |
v = hp->xv[wg0[gc->w]]; |
149 |
< |
d = (double)gc->i[0] / hp->grid[wg0[gc->w]]; |
148 |
> |
v = hp->xv[hdwg0[gc->w]]; |
149 |
> |
d = (double)gc->i[0] / hp->grid[hdwg0[gc->w]]; |
150 |
|
VSUM(cp[0], cp[0], v, d); |
151 |
< |
v = hp->xv[wg1[gc->w]]; |
152 |
< |
d = (double)gc->i[1] / hp->grid[wg1[gc->w]]; |
151 |
> |
v = hp->xv[hdwg1[gc->w]]; |
152 |
> |
d = (double)gc->i[1] / hp->grid[hdwg1[gc->w]]; |
153 |
|
VSUM(cp[0], cp[0], v, d); |
154 |
|
/* compute x1 sums */ |
155 |
< |
v = hp->xv[wg0[gc->w]]; |
156 |
< |
d = 1.0 / hp->grid[wg0[gc->w]]; |
155 |
> |
v = hp->xv[hdwg0[gc->w]]; |
156 |
> |
d = 1.0 / hp->grid[hdwg0[gc->w]]; |
157 |
|
VSUM(cp[1], cp[0], v, d); |
158 |
|
VSUM(cp[3], cp[0], v, d); |
159 |
|
/* compute y1 sums */ |
160 |
< |
v = hp->xv[wg1[gc->w]]; |
161 |
< |
d = 1.0 / hp->grid[wg1[gc->w]]; |
160 |
> |
v = hp->xv[hdwg1[gc->w]]; |
161 |
> |
d = 1.0 / hp->grid[hdwg1[gc->w]]; |
162 |
|
VSUM(cp[2], cp[0], v, d); |
163 |
|
VSUM(cp[3], cp[3], v, d); |
164 |
|
} |
173 |
|
|
174 |
|
for (k = 0; k < 2; k++) { /* compute end points */ |
175 |
|
lseg[k][gc[k].w>>1] = gc[k].w&1 ? hp->grid[gc[k].w>>1]-1 : 0 ; |
176 |
< |
lseg[k][wg0[gc[k].w]] = gc[k].i[0]; |
177 |
< |
lseg[k][wg1[gc[k].w]] = gc[k].i[1]; |
176 |
> |
lseg[k][hdwg0[gc[k].w]] = gc[k].i[0]; |
177 |
> |
lseg[k][hdwg1[gc[k].w]] = gc[k].i[1]; |
178 |
|
} |
179 |
|
return(1); |
180 |
|
} |
186 |
|
double d; |
187 |
|
{ |
188 |
|
double tl = hp->tlin; |
189 |
< |
register unsigned c; |
189 |
> |
register long c; |
190 |
|
|
191 |
|
if (d <= 0.) |
192 |
|
return(0); |
194 |
|
return(DCINF); |
195 |
|
if (d < tl) |
196 |
|
return((unsigned)(d*DCLIN/tl)); |
197 |
< |
c = (unsigned)(log(d/tl)/logstep) + DCLIN; |
198 |
< |
return(c > DCINF ? DCINF : c); |
197 |
> |
c = (long)(log(d/tl)/logstep) + DCLIN; |
198 |
> |
return(c > DCINF ? (unsigned)DCINF : (unsigned)c); |
199 |
|
} |
200 |
|
|
201 |
|
|
206 |
|
{ |
207 |
|
FVECT vt; |
208 |
|
|
209 |
< |
vt[0] = wp[0] - hp->orig[0]; |
210 |
< |
vt[1] = wp[1] - hp->orig[1]; |
211 |
< |
vt[2] = wp[2] - hp->orig[2]; |
212 |
< |
gp[0] = DOT(vt, hp->wn[0]) * hp->wg[0]; |
248 |
< |
gp[1] = DOT(vt, hp->wn[1]) * hp->wg[1]; |
249 |
< |
gp[2] = DOT(vt, hp->wn[2]) * hp->wg[2]; |
209 |
> |
VSUB(vt, wp, hp->orig); |
210 |
> |
gp[0] = DOT(vt, hp->wg[0]); |
211 |
> |
gp[1] = DOT(vt, hp->wg[1]); |
212 |
> |
gp[2] = DOT(vt, hp->wg[2]); |
213 |
|
} |
214 |
|
|
215 |
|
|
251 |
|
d0*cp[1][j] + d1*cp[2][j]; |
252 |
|
} |
253 |
|
VCOPY(ro, p[0]); /* assign ray origin and direction */ |
254 |
< |
rd[0] = p[1][0] - p[0][0]; |
292 |
< |
rd[1] = p[1][1] - p[0][1]; |
293 |
< |
rd[2] = p[1][2] - p[0][2]; |
254 |
> |
VSUB(rd, p[1], p[0]); |
255 |
|
return(normalize(rd)); /* return maximum inside distance */ |
256 |
|
} |
257 |
|
|
271 |
|
/* first, intersect walls */ |
272 |
|
gc[0].w = gc[1].w = -1; |
273 |
|
t0 = -FHUGE; t1 = FHUGE; |
274 |
+ |
VSUB(vt, ro, hp->orig); |
275 |
|
for (i = 0; i < 3; i++) { /* for each wall pair */ |
276 |
< |
d = -DOT(rd, hp->wn[i]); /* plane distance */ |
276 |
> |
d = -DOT(rd, hp->wg[i]); /* plane distance */ |
277 |
|
if (d <= FTINY && d >= -FTINY) /* check for parallel */ |
278 |
|
continue; |
279 |
< |
d1 = DOT(ro, hp->wn[i]); /* ray distances */ |
280 |
< |
d0 = (d1 - hp->wo[i<<1]) / d; |
281 |
< |
d1 = (d1 - hp->wo[i<<1|1]) / d; |
282 |
< |
if (d0 < d1) { /* check against best */ |
279 |
> |
d1 = DOT(vt, hp->wg[i]); /* ray distances */ |
280 |
> |
d0 = d1 / d; |
281 |
> |
d1 = (d1 - hp->grid[i]) / d; |
282 |
> |
if (d < 0) { /* check against best */ |
283 |
|
if (d0 > t0) { |
284 |
|
t0 = d0; |
285 |
|
gc[0].w = i<<1; |
302 |
|
if (gc[0].w < 0 | gc[1].w < 0) /* paranoid check */ |
303 |
|
return(FHUGE); |
304 |
|
/* compute intersections */ |
305 |
< |
for (i = 0; i < 3; i++) { |
306 |
< |
p[0][i] = ro[i] + rd[i]*t0; |
345 |
< |
p[1][i] = ro[i] + rd[i]*t1; |
346 |
< |
} |
305 |
> |
VSUM(p[0], ro, rd, t0); |
306 |
> |
VSUM(p[1], ro, rd, t1); |
307 |
|
/* now, compute grid coordinates */ |
308 |
|
for (i = 0; i < 2; i++) { |
309 |
< |
vt[0] = p[i][0] - hp->orig[0]; |
310 |
< |
vt[1] = p[i][1] - hp->orig[1]; |
311 |
< |
vt[2] = p[i][2] - hp->orig[2]; |
312 |
< |
v = hp->wn[wg0[gc[i].w]]; |
353 |
< |
d = DOT(vt, v) * hp->wg[wg0[gc[i].w]]; |
354 |
< |
if (d < 0. || (gc[i].i[0] = d) >= hp->grid[wg0[gc[i].w]]) |
309 |
> |
VSUB(vt, p[i], hp->orig); |
310 |
> |
v = hp->wg[hdwg0[gc[i].w]]; |
311 |
> |
d = DOT(vt, v); |
312 |
> |
if (d < 0 || d >= hp->grid[hdwg0[gc[i].w]]) |
313 |
|
return(FHUGE); /* outside wall */ |
314 |
+ |
gc[i].i[0] = d; |
315 |
|
if (r != NULL) |
316 |
|
r[i][0] = 256. * (d - gc[i].i[0]); |
317 |
< |
v = hp->wn[wg1[gc[i].w]]; |
318 |
< |
d = DOT(vt, v) * hp->wg[wg1[gc[i].w]]; |
319 |
< |
if (d < 0. || (gc[i].i[1] = d) >= hp->grid[wg1[gc[i].w]]) |
317 |
> |
v = hp->wg[hdwg1[gc[i].w]]; |
318 |
> |
d = DOT(vt, v); |
319 |
> |
if (d < 0 || d >= hp->grid[hdwg1[gc[i].w]]) |
320 |
|
return(FHUGE); /* outside wall */ |
321 |
+ |
gc[i].i[1] = d; |
322 |
|
if (r != NULL) |
323 |
|
r[i][1] = 256. * (d - gc[i].i[1]); |
324 |
|
} |