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 |
|
* Holodeck beam tracking for display process |
6 |
|
*/ |
9 |
|
#include "rhdisp.h" |
10 |
|
#include "rhdriver.h" |
11 |
|
|
12 |
< |
#ifndef MAXDIST |
13 |
< |
#define MAXDIST 42 /* maximum distance outside section */ |
12 |
> |
#ifndef MEYERNG |
13 |
> |
#define MEYERNG 0.2 /* target mean eye range (rel. to grid) */ |
14 |
|
#endif |
15 |
|
|
19 |
– |
#define MAXVOXEL 32 /* maximum number of active voxels */ |
20 |
– |
|
21 |
– |
typedef struct { |
22 |
– |
int hd; /* holodeck section number (-1 if inactive) */ |
23 |
– |
int i[3]; /* voxel index (may be outside section) */ |
24 |
– |
} VOXL; /* a voxel */ |
25 |
– |
|
26 |
– |
static VOXL voxel[MAXVOXEL] = {{-1}}; /* current voxel list */ |
27 |
– |
|
16 |
|
#define CBEAMBLK 1024 /* cbeam allocation block size */ |
17 |
|
|
18 |
< |
static struct beamcomp { |
31 |
< |
int hd; /* holodeck section number */ |
32 |
< |
int bi; /* beam index */ |
33 |
< |
int4 nr; /* number of samples desired */ |
34 |
< |
} *cbeam = NULL; /* current beam list */ |
35 |
< |
|
18 |
> |
static PACKHEAD *cbeam = NULL; /* current beam list */ |
19 |
|
static int ncbeams = 0; /* number of sorted beams in cbeam */ |
20 |
|
static int xcbeams = 0; /* extra (unregistered) beams past ncbeams */ |
21 |
|
static int maxcbeam = 0; /* size of cbeam array */ |
22 |
|
|
23 |
< |
struct cellact { |
41 |
< |
short vi; /* voxel index */ |
42 |
< |
short rev; /* reverse ray direction? */ |
43 |
< |
VIEW *vp; /* view for image */ |
44 |
< |
short hr, vr; /* image resolution */ |
45 |
< |
}; /* action for cell */ |
23 |
> |
VIEWPOINT cureye; /* current eye position */ |
24 |
|
|
25 |
< |
struct beamact { |
26 |
< |
struct cellact ca; /* cell action */ |
27 |
< |
GCOORD gc; /* grid coordinate */ |
28 |
< |
}; /* beam origin and action */ |
25 |
> |
static int newcbeam(void); |
26 |
> |
static int cbeamcmp(const void *cb1, const void *cb2); |
27 |
> |
static int cbeamcmp2(const void *cb1, const void *cb2); |
28 |
> |
static int findcbeam(int hd, int bi); |
29 |
> |
static int getcbeam(int hd, int bi); |
30 |
> |
static void cbeamsort(int adopt); |
31 |
|
|
32 |
|
|
33 |
< |
int |
34 |
< |
newcbeam() /* allocate new entry at end of cbeam array */ |
33 |
> |
static int |
34 |
> |
newcbeam(void) /* allocate new entry at end of cbeam array */ |
35 |
|
{ |
36 |
|
int i; |
37 |
|
|
38 |
|
if ((i = ncbeams + xcbeams++) >= maxcbeam) { /* grow array */ |
39 |
|
maxcbeam += CBEAMBLK; |
40 |
|
if (cbeam == NULL) |
41 |
< |
cbeam = (struct beamcomp *)malloc( |
42 |
< |
maxcbeam*sizeof(struct beamcomp) ); |
41 |
> |
cbeam = (PACKHEAD *)malloc( |
42 |
> |
maxcbeam*sizeof(PACKHEAD) ); |
43 |
|
else |
44 |
< |
cbeam = (struct beamcomp *)realloc( (char *)cbeam, |
45 |
< |
maxcbeam*sizeof(struct beamcomp) ); |
44 |
> |
cbeam = (PACKHEAD *)realloc((void *)cbeam, |
45 |
> |
maxcbeam*sizeof(PACKHEAD) ); |
46 |
|
if (cbeam == NULL) |
47 |
|
error(SYSTEM, "out of memory in newcbeam"); |
48 |
|
} |
50 |
|
} |
51 |
|
|
52 |
|
|
53 |
< |
int |
54 |
< |
cbeamcmp(cb1, cb2) /* compare two cbeam entries for sort: keep orphans */ |
55 |
< |
register struct beamcomp *cb1, *cb2; |
53 |
> |
static int |
54 |
> |
cbeamcmp( /* compare two cbeam entries for sort: keep orphans */ |
55 |
> |
const void *cb1, |
56 |
> |
const void *cb2 |
57 |
> |
) |
58 |
|
{ |
59 |
< |
register int c; |
59 |
> |
int c; |
60 |
|
|
61 |
< |
if ((c = cb1->bi - cb2->bi)) /* sort on beam index first */ |
61 |
> |
if ((c = ((PACKHEAD*)cb1)->bi - ((PACKHEAD*)cb2)->bi)) /* sort on beam index first */ |
62 |
|
return(c); |
63 |
< |
return(cb1->hd - cb2->hd); /* use hd to resolve matches */ |
63 |
> |
return(((PACKHEAD*)cb1)->hd - ((PACKHEAD*)cb2)->hd); /* use hd to resolve matches */ |
64 |
|
} |
65 |
|
|
66 |
|
|
67 |
< |
int |
68 |
< |
cbeamcmp2(cb1, cb2) /* compare two cbeam entries for sort: no orphans */ |
69 |
< |
register struct beamcomp *cb1, *cb2; |
67 |
> |
static int |
68 |
> |
cbeamcmp2( /* compare two cbeam entries for sort: no orphans */ |
69 |
> |
const void *cb1, |
70 |
> |
const void *cb2 |
71 |
> |
) |
72 |
|
{ |
73 |
< |
register int c; |
73 |
> |
int c; |
74 |
|
|
75 |
< |
if (!cb1->nr) /* put orphans at the end, unsorted */ |
76 |
< |
return(cb2->nr); |
77 |
< |
if (!cb2->nr) |
75 |
> |
if (!((PACKHEAD*)cb1)->nr) /* put orphans at the end, unsorted */ |
76 |
> |
return(((PACKHEAD*)cb2)->nr); |
77 |
> |
if (!((PACKHEAD*)cb2)->nr) |
78 |
|
return(-1); |
79 |
< |
if ((c = cb1->bi - cb2->bi)) /* sort on beam index first */ |
79 |
> |
if ((c = ((PACKHEAD*)cb1)->bi - ((PACKHEAD*)cb2)->bi)) /* sort on beam index first */ |
80 |
|
return(c); |
81 |
< |
return(cb1->hd - cb2->hd); /* use hd to resolve matches */ |
81 |
> |
return(((PACKHEAD*)cb1)->hd - ((PACKHEAD*)cb2)->hd); /* use hd to resolve matches */ |
82 |
|
} |
83 |
|
|
84 |
|
|
85 |
< |
int |
86 |
< |
findcbeam(hd, bi) /* find the specified beam in our sorted list */ |
87 |
< |
int hd, bi; |
85 |
> |
static int |
86 |
> |
findcbeam( /* find the specified beam in our sorted list */ |
87 |
> |
int hd, |
88 |
> |
int bi |
89 |
> |
) |
90 |
|
{ |
91 |
< |
struct beamcomp cb; |
92 |
< |
register struct beamcomp *p; |
91 |
> |
PACKHEAD cb; |
92 |
> |
PACKHEAD *p; |
93 |
|
|
94 |
|
if (ncbeams <= 0) |
95 |
|
return(-1); |
96 |
< |
cb.hd = hd; cb.bi = bi; cb.nr = 0; |
97 |
< |
p = (struct beamcomp *)bsearch((char *)&cb, (char *)cbeam, ncbeams, |
98 |
< |
sizeof(struct beamcomp), cbeamcmp); |
96 |
> |
cb.hd = hd; cb.bi = bi; cb.nr = cb.nc = 0; |
97 |
> |
p = (PACKHEAD *)bsearch((char *)&cb, (char *)cbeam, ncbeams, |
98 |
> |
sizeof(PACKHEAD), cbeamcmp); |
99 |
|
if (p == NULL) |
100 |
|
return(-1); |
101 |
|
return(p - cbeam); |
102 |
|
} |
103 |
|
|
104 |
|
|
105 |
< |
int |
106 |
< |
getcbeam(hd, bi) /* get the specified beam, allocating as necessary */ |
107 |
< |
register int hd; |
108 |
< |
int bi; |
105 |
> |
static int |
106 |
> |
getcbeam( /* get the specified beam, allocating as necessary */ |
107 |
> |
int hd, |
108 |
> |
int bi |
109 |
> |
) |
110 |
|
{ |
111 |
< |
register int n; |
111 |
> |
int n; |
112 |
|
/* first, look in sorted list */ |
113 |
|
if ((n = findcbeam(hd, bi)) >= 0) |
114 |
|
return(n); |
117 |
|
if (cbeam[n].bi == bi && cbeam[n].hd == hd) |
118 |
|
return(n); |
119 |
|
/* check legality */ |
120 |
< |
if (hd < 0 | hd >= HDMAX || hdlist[hd] == NULL) |
120 |
> |
if ((hd < 0) | (hd >= HDMAX) || hdlist[hd] == NULL) |
121 |
|
error(INTERNAL, "illegal holodeck number in getcbeam"); |
122 |
< |
if (bi < 1 | bi > nbeams(hdlist[hd])) |
122 |
> |
if ((bi < 1) | (bi > nbeams(hdlist[hd]))) |
123 |
|
error(INTERNAL, "illegal beam index in getcbeam"); |
124 |
|
n = newcbeam(); /* allocate and assign */ |
125 |
< |
cbeam[n].nr = 0; cbeam[n].hd = hd; cbeam[n].bi = bi; |
125 |
> |
cbeam[n].hd = hd; cbeam[n].bi = bi; cbeam[n].nr = cbeam[n].nc = 0; |
126 |
|
return(n); |
127 |
|
} |
128 |
|
|
129 |
|
|
130 |
< |
cbeamsort(adopt) /* sort our beam list, possibly turning out orphans */ |
131 |
< |
int adopt; |
130 |
> |
static void |
131 |
> |
cbeamsort( /* sort our beam list, possibly turning out orphans */ |
132 |
> |
int adopt |
133 |
> |
) |
134 |
|
{ |
135 |
< |
register int i; |
135 |
> |
int i; |
136 |
|
|
137 |
|
if (!(ncbeams += xcbeams)) |
138 |
|
return; |
139 |
|
xcbeams = 0; |
140 |
< |
qsort((char *)cbeam, ncbeams, sizeof(struct beamcomp), |
140 |
> |
qsort((char *)cbeam, ncbeams, sizeof(PACKHEAD), |
141 |
|
adopt ? cbeamcmp : cbeamcmp2); |
142 |
|
if (adopt) |
143 |
|
return; |
149 |
|
} |
150 |
|
|
151 |
|
|
152 |
< |
cbeamop(op, bl, n) /* update beams on server list */ |
153 |
< |
int op; |
154 |
< |
register struct beamcomp *bl; |
155 |
< |
int n; |
152 |
> |
void |
153 |
> |
beam_init( /* clear beam list for new view(s) */ |
154 |
> |
int fresh |
155 |
> |
) |
156 |
|
{ |
157 |
< |
register PACKHEAD *pa; |
169 |
< |
register int i; |
157 |
> |
int i; |
158 |
|
|
171 |
– |
if (n <= 0) |
172 |
– |
return; |
173 |
– |
pa = (PACKHEAD *)malloc(n*sizeof(PACKHEAD)); |
174 |
– |
if (pa == NULL) |
175 |
– |
error(SYSTEM, "out of memory in cbeamop"); |
176 |
– |
for (i = 0; i < n; i++) { |
177 |
– |
pa[i].hd = bl[i].hd; |
178 |
– |
pa[i].bi = bl[i].bi; |
179 |
– |
pa[i].nr = bl[i].nr; |
180 |
– |
pa[i].nc = 0; |
181 |
– |
} |
182 |
– |
serv_request(op, n*sizeof(PACKHEAD), (char *)pa); |
183 |
– |
free((char *)pa); |
184 |
– |
} |
185 |
– |
|
186 |
– |
|
187 |
– |
unsigned int4 |
188 |
– |
add_voxels(vp) /* add voxels corresponding to view point */ |
189 |
– |
FVECT vp; |
190 |
– |
{ |
191 |
– |
int first, n, rfl = 0; |
192 |
– |
FVECT gp; |
193 |
– |
double d; |
194 |
– |
int dist, bestd = 0x7fff; |
195 |
– |
VOXL vox; |
196 |
– |
register int i, j, k; |
197 |
– |
/* count voxels in list already */ |
198 |
– |
for (first = 0; first < MAXVOXEL && voxel[first].hd >= 0; first++) |
199 |
– |
; |
200 |
– |
/* find closest voxels */ |
201 |
– |
for (n = first, i = 0; n < MAXVOXEL && hdlist[i]; i++) { |
202 |
– |
hdgrid(gp, hdlist[i], vp); |
203 |
– |
for (j = 0; n < MAXVOXEL && j < 8; j++) { |
204 |
– |
dist = 0; |
205 |
– |
for (k = 0; k < 3; k++) { |
206 |
– |
d = gp[k] - .5 + (j>>k & 1); |
207 |
– |
if (d < 0.) |
208 |
– |
dist += -(vox.i[k] = (int)d - 1); |
209 |
– |
else if ((vox.i[k] = d) >= hdlist[i]->grid[k]) |
210 |
– |
dist += vox.i[k] - |
211 |
– |
hdlist[i]->grid[k] + 1; |
212 |
– |
} |
213 |
– |
if (dist > bestd) /* others were closer */ |
214 |
– |
continue; |
215 |
– |
if (dist < bestd) { /* start closer list */ |
216 |
– |
n = first; |
217 |
– |
bestd = dist; |
218 |
– |
rfl = 0; |
219 |
– |
} |
220 |
– |
/* check if already in list */ |
221 |
– |
for (k = first; k--; ) |
222 |
– |
if (voxel[k].hd == i && |
223 |
– |
voxel[k].i[0] == vox.i[0] && |
224 |
– |
voxel[k].i[1] == vox.i[1] && |
225 |
– |
voxel[k].i[2] == vox.i[2]) |
226 |
– |
break; |
227 |
– |
if (k >= 0) { |
228 |
– |
rfl |= 1<<k; |
229 |
– |
continue; |
230 |
– |
} |
231 |
– |
vox.hd = i; /* add this voxel */ |
232 |
– |
copystruct(&voxel[n], &vox); |
233 |
– |
rfl |= 1<<n++; |
234 |
– |
} |
235 |
– |
} |
236 |
– |
/* check for really stupid move */ |
237 |
– |
if (bestd > MAXDIST) { |
238 |
– |
error(COMMAND, "move past outer limits"); |
239 |
– |
return(0); |
240 |
– |
} |
241 |
– |
if (n < MAXVOXEL) |
242 |
– |
voxel[n].hd = -1; |
243 |
– |
return(rfl); |
244 |
– |
} |
245 |
– |
|
246 |
– |
|
247 |
– |
int |
248 |
– |
dobeam(gcp, bp) /* express interest in a beam */ |
249 |
– |
GCOORD *gcp; |
250 |
– |
register struct beamact *bp; |
251 |
– |
{ |
252 |
– |
GCOORD gc[2]; |
253 |
– |
int bi, i, n; |
254 |
– |
/* compute beam index */ |
255 |
– |
if (bp->ca.rev) { |
256 |
– |
copystruct(gc, &bp->gc); |
257 |
– |
copystruct(gc+1, gcp); |
258 |
– |
} else { |
259 |
– |
copystruct(gc, gcp); |
260 |
– |
copystruct(gc+1, &bp->gc); |
261 |
– |
} |
262 |
– |
if ((bi = hdbindex(hdlist[voxel[bp->ca.vi].hd], gc)) <= 0) |
263 |
– |
error(CONSISTENCY, "bad grid coordinate in dobeam"); |
264 |
– |
/* add it in */ |
265 |
– |
i = getcbeam(voxel[bp->ca.vi].hd, bi); |
266 |
– |
n = npixels(bp->ca.vp, bp->ca.hr, bp->ca.vr, |
267 |
– |
hdlist[cbeam[i].hd], cbeam[i].bi); |
268 |
– |
if (n > cbeam[i].nr) |
269 |
– |
cbeam[i].nr = n; |
270 |
– |
return(i == ncbeams+xcbeams-1); /* return 1 if totally new */ |
271 |
– |
} |
272 |
– |
|
273 |
– |
|
274 |
– |
|
275 |
– |
int |
276 |
– |
docell(gcp, cap) /* find beams corresponding to cell and voxel */ |
277 |
– |
GCOORD *gcp; |
278 |
– |
register struct cellact *cap; |
279 |
– |
{ |
280 |
– |
register HOLO *hp = hdlist[voxel[cap->vi].hd]; |
281 |
– |
FVECT org, dir[4]; |
282 |
– |
FVECT vgp, cgp, vc; |
283 |
– |
FVECT v1, v2; |
284 |
– |
struct beamact bo; |
285 |
– |
int axmax, j; |
286 |
– |
double d, avmax; |
287 |
– |
register int i; |
288 |
– |
/* compute cell center */ |
289 |
– |
cgp[gcp->w>>1] = gcp->w&1 ? hp->grid[gcp->w>>1] : 0 ; |
290 |
– |
cgp[hdwg0[gcp->w]] = gcp->i[0] + .5; |
291 |
– |
cgp[hdwg1[gcp->w]] = gcp->i[1] + .5; |
292 |
– |
hdworld(org, hp, cgp); |
293 |
– |
/* compute direction to voxel center */ |
294 |
– |
for (i = 3; i--; ) |
295 |
– |
vgp[i] = voxel[cap->vi].i[i] + .5; |
296 |
– |
hdworld(vc, hp, vgp); |
297 |
– |
for (i = 3; i--; ) |
298 |
– |
vc[i] -= org[i]; |
299 |
– |
/* compute maximum area axis */ |
300 |
– |
axmax = -1; avmax = 0; |
301 |
– |
for (i = 3; i--; ) { |
302 |
– |
d = vgp[i] - cgp[i]; |
303 |
– |
if (d < 0.) d = -d; |
304 |
– |
if (d > avmax) { |
305 |
– |
avmax = d; |
306 |
– |
axmax = i; |
307 |
– |
} |
308 |
– |
} |
309 |
– |
#ifdef DEBUG |
310 |
– |
if (axmax < 0) |
311 |
– |
error(CONSISTENCY, "botched axis computation in docell"); |
312 |
– |
#endif |
313 |
– |
/* compute offset vectors */ |
314 |
– |
d = 0.5/hp->grid[j=(axmax+1)%3]; |
315 |
– |
for (i = 3; i--; ) |
316 |
– |
v1[i] = hp->xv[j][i] * d; |
317 |
– |
d = 0.5/hp->grid[j=(axmax+2)%3]; |
318 |
– |
if (DOT(hp->wg[axmax], vc) < 0.) |
319 |
– |
d = -d; /* reverse vertex order */ |
320 |
– |
for (i = 3; i--; ) |
321 |
– |
v2[i] = hp->xv[j][i] * d; |
322 |
– |
/* compute voxel pyramid */ |
323 |
– |
for (i = 3; i--; ) { |
324 |
– |
dir[0][i] = vc[i] - v1[i] - v2[i]; |
325 |
– |
dir[1][i] = vc[i] + v1[i] - v2[i]; |
326 |
– |
dir[2][i] = vc[i] + v1[i] + v2[i]; |
327 |
– |
dir[3][i] = vc[i] - v1[i] + v2[i]; |
328 |
– |
} |
329 |
– |
/* visit beams for opposite cells */ |
330 |
– |
copystruct(&bo.ca, cap); |
331 |
– |
copystruct(&bo.gc, gcp); |
332 |
– |
return(visit_cells(org, dir, hp, dobeam, &bo)); |
333 |
– |
} |
334 |
– |
|
335 |
– |
|
336 |
– |
int |
337 |
– |
doview(cap) /* visit cells for a given view */ |
338 |
– |
struct cellact *cap; |
339 |
– |
{ |
340 |
– |
int orient; |
341 |
– |
FVECT org, dir[4]; |
342 |
– |
/* compute view pyramid */ |
343 |
– |
orient = viewpyramid(org, dir, hdlist[voxel[cap->vi].hd], cap->vp); |
344 |
– |
if (!orient) |
345 |
– |
error(INTERNAL, "unusable view in doview"); |
346 |
– |
cap->rev = orient < 0; |
347 |
– |
/* visit cells within pyramid */ |
348 |
– |
return(visit_cells(org, dir, hdlist[voxel[cap->vi].hd], docell, cap)); |
349 |
– |
} |
350 |
– |
|
351 |
– |
|
352 |
– |
beam_init(fresh) /* clear beam list for new view(s) */ |
353 |
– |
int fresh; |
354 |
– |
{ |
355 |
– |
register int i; |
356 |
– |
|
159 |
|
if (fresh) /* discard old beams? */ |
160 |
|
ncbeams = xcbeams = 0; |
161 |
|
else /* else clear sample requests */ |
162 |
|
for (i = ncbeams+xcbeams; i--; ) |
163 |
|
cbeam[i].nr = 0; |
164 |
< |
voxel[0].hd = -1; /* clear voxel list */ |
164 |
> |
cureye.rng = 0.; |
165 |
|
} |
166 |
|
|
167 |
|
|
168 |
< |
beam_view(vn, hr, vr) /* add beam view (if advisable) */ |
169 |
< |
VIEW *vn; |
170 |
< |
int hr, vr; |
168 |
> |
int16 * |
169 |
> |
beam_view( /* add beam view (if advisable) */ |
170 |
> |
VIEW *vn, |
171 |
> |
int hr, |
172 |
> |
int vr |
173 |
> |
) |
174 |
|
{ |
175 |
< |
struct cellact ca; |
176 |
< |
unsigned int4 vfl; |
177 |
< |
/* sort our list */ |
175 |
> |
int16 *slist; |
176 |
> |
BEAMLIST blist; |
177 |
> |
double eravg, d; |
178 |
> |
HOLO *hp; |
179 |
> |
int i, n; |
180 |
> |
/* compute beams for view */ |
181 |
> |
slist = viewbeams(vn, hr, vr, &blist); |
182 |
> |
if (*slist < 0) { |
183 |
> |
error(COMMAND, "no sections visible from this view"); |
184 |
> |
return(NULL); |
185 |
> |
} |
186 |
> |
/* sort current beam list */ |
187 |
|
cbeamsort(1); |
188 |
< |
/* add new voxels */ |
189 |
< |
vfl = add_voxels(vn->vp); |
190 |
< |
if (!vfl) |
191 |
< |
return(0); |
192 |
< |
ca.vp = vn; ca.hr = hr; ca.vr = vr; |
193 |
< |
/* update our beam list */ |
194 |
< |
for (ca.vi = 0; vfl; vfl >>= 1, ca.vi++) |
195 |
< |
if (vfl & 1) |
196 |
< |
doview(&ca); |
197 |
< |
return(1); |
188 |
> |
/* add new beams to list */ |
189 |
> |
for (i = blist.nb; i--; ) { |
190 |
> |
n = getcbeam(blist.bl[i].hd, blist.bl[i].bi); |
191 |
> |
if (blist.bl[i].nr > cbeam[n].nr) |
192 |
> |
cbeam[n].nr = blist.bl[i].nr; |
193 |
> |
} |
194 |
> |
free((void *)blist.bl); /* free list */ |
195 |
> |
if (MEYERNG <= FTINY) |
196 |
> |
return(slist); |
197 |
> |
/* compute average eye range */ |
198 |
> |
eravg = 0.; |
199 |
> |
for (n = 0; slist[n] >= 0; n++) { |
200 |
> |
hp = hdlist[slist[n]]; |
201 |
> |
eravg += MEYERNG/3. / VLEN(hp->wg[0]) + |
202 |
> |
MEYERNG/3. / VLEN(hp->wg[1]) + |
203 |
> |
MEYERNG/3. / VLEN(hp->wg[2]) ; |
204 |
> |
} |
205 |
> |
eravg /= (double)n; |
206 |
> |
/* add to current eye position */ |
207 |
> |
if (cureye.rng <= FTINY) { |
208 |
> |
VCOPY(cureye.vpt, vn->vp); |
209 |
> |
cureye.rng = eravg; |
210 |
> |
} else if ((d = sqrt(dist2(vn->vp,cureye.vpt))) + eravg > cureye.rng) { |
211 |
> |
for (i = 3; i--; ) |
212 |
> |
cureye.vpt[i] = 0.5*(cureye.vpt[i] + vn->vp[i]); |
213 |
> |
cureye.rng = 0.5*(cureye.rng + eravg + d); |
214 |
> |
} |
215 |
> |
return(slist); |
216 |
|
} |
217 |
|
|
218 |
|
|
219 |
|
int |
220 |
< |
beam_sync(all) /* update beam list on server */ |
221 |
< |
int all; |
220 |
> |
beam_sync( /* update beam list on server */ |
221 |
> |
int all |
222 |
> |
) |
223 |
|
{ |
224 |
+ |
/* set new eye position */ |
225 |
+ |
serv_request(DR_VIEWPOINT, sizeof(VIEWPOINT), (char *)&cureye); |
226 |
|
/* sort list (put orphans at end) */ |
227 |
|
cbeamsort(all < 0); |
228 |
< |
if (all) |
229 |
< |
cbeamop(DR_NEWSET, cbeam, ncbeams); |
230 |
< |
else |
231 |
< |
cbeamop(DR_ADJSET, cbeam, ncbeams+xcbeams); |
228 |
> |
/* send beam request */ |
229 |
> |
if (all) { |
230 |
> |
if (ncbeams > 0) |
231 |
> |
serv_request(DR_NEWSET, |
232 |
> |
ncbeams*sizeof(PACKHEAD), (char *)cbeam); |
233 |
> |
} else { |
234 |
> |
if (ncbeams+xcbeams > 0) |
235 |
> |
serv_request(DR_ADJSET, |
236 |
> |
(ncbeams+xcbeams)*sizeof(PACKHEAD), (char *)cbeam); |
237 |
> |
} |
238 |
|
xcbeams = 0; /* truncate our list */ |
239 |
|
return(ncbeams); |
240 |
+ |
} |
241 |
+ |
|
242 |
+ |
|
243 |
+ |
void |
244 |
+ |
gridlines( /* run through holodeck section grid lines */ |
245 |
+ |
void (*f)(FVECT wp[2]) |
246 |
+ |
) |
247 |
+ |
{ |
248 |
+ |
int hd, w, i; |
249 |
+ |
int g0, g1; |
250 |
+ |
FVECT wp[2], mov; |
251 |
+ |
double d; |
252 |
+ |
/* do each wall on each section */ |
253 |
+ |
for (hd = 0; hdlist[hd] != NULL; hd++) |
254 |
+ |
for (w = 0; w < 6; w++) { |
255 |
+ |
g0 = hdwg0[w]; |
256 |
+ |
g1 = hdwg1[w]; |
257 |
+ |
d = 1.0/hdlist[hd]->grid[g0]; |
258 |
+ |
mov[0] = d * hdlist[hd]->xv[g0][0]; |
259 |
+ |
mov[1] = d * hdlist[hd]->xv[g0][1]; |
260 |
+ |
mov[2] = d * hdlist[hd]->xv[g0][2]; |
261 |
+ |
if (w & 1) { |
262 |
+ |
VSUM(wp[0], hdlist[hd]->orig, |
263 |
+ |
hdlist[hd]->xv[w>>1], 1.); |
264 |
+ |
VSUM(wp[0], wp[0], mov, 1.); |
265 |
+ |
} else |
266 |
+ |
VCOPY(wp[0], hdlist[hd]->orig); |
267 |
+ |
VSUM(wp[1], wp[0], hdlist[hd]->xv[g1], 1.); |
268 |
+ |
for (i = hdlist[hd]->grid[g0]; ; ) { /* g0 lines */ |
269 |
+ |
(*f)(wp); |
270 |
+ |
if (!--i) break; |
271 |
+ |
wp[0][0] += mov[0]; wp[0][1] += mov[1]; |
272 |
+ |
wp[0][2] += mov[2]; wp[1][0] += mov[0]; |
273 |
+ |
wp[1][1] += mov[1]; wp[1][2] += mov[2]; |
274 |
+ |
} |
275 |
+ |
d = 1.0/hdlist[hd]->grid[g1]; |
276 |
+ |
mov[0] = d * hdlist[hd]->xv[g1][0]; |
277 |
+ |
mov[1] = d * hdlist[hd]->xv[g1][1]; |
278 |
+ |
mov[2] = d * hdlist[hd]->xv[g1][2]; |
279 |
+ |
if (w & 1) |
280 |
+ |
VSUM(wp[0], hdlist[hd]->orig, |
281 |
+ |
hdlist[hd]->xv[w>>1], 1.); |
282 |
+ |
else |
283 |
+ |
VSUM(wp[0], hdlist[hd]->orig, mov, 1.); |
284 |
+ |
VSUM(wp[1], wp[0], hdlist[hd]->xv[g0], 1.); |
285 |
+ |
for (i = hdlist[hd]->grid[g1]; ; ) { /* g1 lines */ |
286 |
+ |
(*f)(wp); |
287 |
+ |
if (!--i) break; |
288 |
+ |
wp[0][0] += mov[0]; wp[0][1] += mov[1]; |
289 |
+ |
wp[0][2] += mov[2]; wp[1][0] += mov[0]; |
290 |
+ |
wp[1][1] += mov[1]; wp[1][2] += mov[2]; |
291 |
+ |
} |
292 |
+ |
} |
293 |
|
} |