84 |
|
* The ray directions that define the pyramid in visit_cells() needn't |
85 |
|
* be normalized, but they must be given in clockwise order as seen |
86 |
|
* from the pyramid's apex (origin). |
87 |
+ |
* If no cell centers fall within the domain, the closest cell is visited. |
88 |
|
*/ |
89 |
|
int |
90 |
|
visit_cells(orig, pyrd, hp, vf, dp) /* visit cells within a pyramid */ |
91 |
|
FVECT orig, pyrd[4]; /* pyramid ray directions in clockwise order */ |
92 |
< |
HOLO *hp; |
92 |
> |
register HOLO *hp; |
93 |
|
int (*vf)(); |
94 |
|
char *dp; |
95 |
|
{ |
96 |
< |
int n = 0; |
96 |
> |
int ncalls = 0, n = 0; |
97 |
|
int inflags = 0; |
98 |
|
FVECT gp, pn[4], lo, ld; |
99 |
|
double po[4], lbeg, lend, d, t; |
100 |
< |
GCOORD gc; |
100 |
> |
GCOORD gc, gc2[2]; |
101 |
|
register int i; |
102 |
|
/* figure out whose side we're on */ |
103 |
|
hdgrid(gp, hp, orig); |
143 |
|
if (lbeg >= lend) |
144 |
|
continue; |
145 |
|
i = lend + .5; /* visit cells on this scan */ |
146 |
< |
for (gc.i[0] = lbeg + .5; gc.i[0] < i; gc.i[0]++) |
146 |
> |
for (gc.i[0] = lbeg + .5; gc.i[0] < i; gc.i[0]++) { |
147 |
|
n += (*vf)(&gc, dp); |
148 |
+ |
ncalls++; |
149 |
+ |
} |
150 |
|
} |
151 |
|
} |
152 |
< |
return(n); |
152 |
> |
if (ncalls) /* got one at least */ |
153 |
> |
return(n); |
154 |
> |
/* else find closest cell */ |
155 |
> |
VSUM(ld, pyrd[0], pyrd[1], 1.); |
156 |
> |
VSUM(ld, ld, pyrd[2], 1.); |
157 |
> |
VSUM(ld, ld, pyrd[3], 1.); |
158 |
> |
#if 0 |
159 |
> |
if (normalize(ld) == 0.0) /* technically not necessary */ |
160 |
> |
return(0); |
161 |
> |
#endif |
162 |
> |
d = hdinter(gc2, NULL, &t, hp, orig, ld); |
163 |
> |
if (d >= FHUGE || t <= 0.) |
164 |
> |
return(0); |
165 |
> |
return((*vf)(gc2+1, dp)); /* visit it */ |
166 |
|
} |
167 |
|
|
168 |
|
|
286 |
|
return(cl.cl); |
287 |
|
memerr: |
288 |
|
error(SYSTEM, "out of memory in getviewcells"); |
289 |
+ |
} |
290 |
+ |
|
291 |
+ |
|
292 |
+ |
gridlines(f) /* run through holodeck section grid lines */ |
293 |
+ |
int (*f)(); |
294 |
+ |
{ |
295 |
+ |
register int hd, w, i; |
296 |
+ |
int g0, g1; |
297 |
+ |
FVECT wp[2], mov; |
298 |
+ |
double d; |
299 |
+ |
/* do each wall on each section */ |
300 |
+ |
for (hd = 0; hdlist[hd] != NULL; hd++) |
301 |
+ |
for (w = 0; w < 6; w++) { |
302 |
+ |
g0 = ((w>>1)+1)%3; |
303 |
+ |
g1 = ((w>>1)+2)%3; |
304 |
+ |
d = 1.0/hdlist[hd]->grid[g0]; |
305 |
+ |
mov[0] = d * hdlist[hd]->xv[g0][0]; |
306 |
+ |
mov[1] = d * hdlist[hd]->xv[g0][1]; |
307 |
+ |
mov[2] = d * hdlist[hd]->xv[g0][2]; |
308 |
+ |
if (w & 1) { |
309 |
+ |
VSUM(wp[0], hdlist[hd]->orig, |
310 |
+ |
hdlist[hd]->xv[w>>1], 1.); |
311 |
+ |
VSUM(wp[0], wp[0], mov, 1.); |
312 |
+ |
} else |
313 |
+ |
VCOPY(wp[0], hdlist[hd]->orig); |
314 |
+ |
VSUM(wp[1], wp[0], hdlist[hd]->xv[g1], 1.); |
315 |
+ |
for (i = hdlist[hd]->grid[g0]; ; ) { /* g0 lines */ |
316 |
+ |
(*f)(wp); |
317 |
+ |
if (!--i) break; |
318 |
+ |
wp[0][0] += mov[0]; wp[0][1] += mov[1]; |
319 |
+ |
wp[0][2] += mov[2]; wp[1][0] += mov[0]; |
320 |
+ |
wp[1][1] += mov[1]; wp[1][2] += mov[2]; |
321 |
+ |
} |
322 |
+ |
d = 1.0/hdlist[hd]->grid[g1]; |
323 |
+ |
mov[0] = d * hdlist[hd]->xv[g1][0]; |
324 |
+ |
mov[1] = d * hdlist[hd]->xv[g1][1]; |
325 |
+ |
mov[2] = d * hdlist[hd]->xv[g1][2]; |
326 |
+ |
if (w & 1) |
327 |
+ |
VSUM(wp[0], hdlist[hd]->orig, |
328 |
+ |
hdlist[hd]->xv[w>>1], 1.); |
329 |
+ |
else |
330 |
+ |
VSUM(wp[0], hdlist[hd]->orig, mov, 1.); |
331 |
+ |
VSUM(wp[1], wp[0], hdlist[hd]->xv[g0], 1.); |
332 |
+ |
for (i = hdlist[hd]->grid[g1]; ; ) { /* g1 lines */ |
333 |
+ |
(*f)(wp); |
334 |
+ |
if (!--i) break; |
335 |
+ |
wp[0][0] += mov[0]; wp[0][1] += mov[1]; |
336 |
+ |
wp[0][2] += mov[2]; wp[1][0] += mov[0]; |
337 |
+ |
wp[1][1] += mov[1]; wp[1][2] += mov[2]; |
338 |
+ |
} |
339 |
+ |
} |
340 |
|
} |