139 const float rootOf2 = 1.414213f;
140 const float halfRoot2 = rootOf2 / 2;
142 if (t < 0 || t >= 1)
return -1;
143 if (!(t < 0) && !(t >= 0))
return -1;
157 result.
x = pos.x + cell_result.x * scale_u;
158 result.
y = cell_height;
159 result.
z = pos.y +
height - cell_result.y * scale_v;
171 float tToU = eu * fabs (oneOverdu);
172 float tToV = ev * fabs (oneOverdv);
173 float tToP = ep * fabs (oneOverdp);
175 if (tToU <= tToV && tToU <= tToP)
178 if (t + tToU > 1) tToU = 1 - t;
185 ev -= fabs(dv) * tToU;
186 ep -= fabs(dp) * tToU;
191 else if (tToV <= tToU && tToV <= tToP)
194 if (t + tToV > 1) tToV = 1 - t;
200 eu -= fabs(du) * tToV;
202 ep -= fabs(dp) * tToV;
210 if (t + tToP > 1) tToP = 1 - t;
216 eu -= fabs(du) * tToP;
217 ev -= fabs(dv) * tToP;
227 if (ep <= 0) ep = halfRoot2;
234 float h_h0 = cell_height;
236 csVector2 uv = csVector2 ((u0 + du * t) * scale_u,
237 (v0 + dv * t) * scale_v);
238 float h_h1 = cell->GetHeight (uv);
244 int cmp_h0 = sign (r_h0 - h_h0);
245 int cmp_h1 = sign (r_h1 - h_h1);
247 if (cmp_h0 * cmp_h1 == -1 || fabs (r_h1 - h_h1) <
EPSILON)
251 if (cmp_h0 * cmp_h1 == -1)
257 float coeff = fabs(r_h0 - h_h0) / fabs(r_h1 - h_h1);
264 correct_t -= tstep / (coeff + 1);
267 cell_result.x = u0 + du * correct_t;
268 cell_result.y = v0 + dv * correct_t;
270 result.
x = pos.x + cell_result.x * scale_u;
271 result.
y = h0 + dh * correct_t;
272 result.
z = pos.y +
height - cell_result.y * scale_v;
274 return (cell_result.x >=0 && cell_result.x <=
width - 1 &&
275 cell_result.y >=0 && cell_result.y <=
height - 1);