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); |
115 |
|
if (!(inflags & 1<<gc.w)) /* origin on wrong side */ |
116 |
|
continue; |
117 |
|
/* scanline algorithm */ |
118 |
< |
for (gc.i[1] = hp->grid[((gc.w>>1)+2)%3]; gc.i[1]--; ) { |
118 |
> |
for (gc.i[1] = hp->grid[hdwg1[gc.w]]; gc.i[1]--; ) { |
119 |
|
/* compute scanline */ |
120 |
|
gp[gc.w>>1] = gc.w&1 ? hp->grid[gc.w>>1] : 0; |
121 |
< |
gp[((gc.w>>1)+1)%3] = 0; |
122 |
< |
gp[((gc.w>>1)+2)%3] = gc.i[1] + 0.5; |
121 |
> |
gp[hdwg0[gc.w]] = 0; |
122 |
> |
gp[hdwg1[gc.w]] = gc.i[1] + 0.5; |
123 |
|
hdworld(lo, hp, gp); |
124 |
< |
gp[((gc.w>>1)+1)%3] = 1; |
124 |
> |
gp[hdwg0[gc.w]] = 1; |
125 |
|
hdworld(ld, hp, gp); |
126 |
|
ld[0] -= lo[0]; ld[1] -= lo[1]; ld[2] -= lo[2]; |
127 |
|
/* find scanline limits */ |
128 |
< |
lbeg = 0; lend = hp->grid[((gc.w>>1)+1)%3]; |
128 |
> |
lbeg = 0; lend = hp->grid[hdwg0[gc.w]]; |
129 |
|
for (i = 0; i < 4; i++) { |
130 |
|
t = DOT(pn[i], lo) - po[i]; |
131 |
|
d = -DOT(pn[i], ld); |
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 |
|
|
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; |
302 |
> |
g0 = hdwg0[w]; |
303 |
> |
g1 = hdwg1[w]; |
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]; |