Fix usage of uninitialized waypoint array variables in ConfusedMovementGenerator<T>::Initialize and revert 9b1c565510+ad8ce5245e that covered up this problem without fixing it and introduced a faulty LOS calculation.

With thanks to Lynx3d and click, and Aokromes and ritchy for testing.

--HG--
branch : trunk
This commit is contained in:
Machiavelli
2010-06-19 17:26:12 +02:00
parent 706c0568a5
commit 8c8986b2bc
4 changed files with 17 additions and 31 deletions

View File

@@ -146,32 +146,19 @@ namespace VMAP
bool StaticMapTree::isInLineOfSight(const Vector3& pos1, const Vector3& pos2) const
{
bool result = false;
bool result = true;
float maxDist = (pos2 - pos1).magnitude();
// valid map coords should *never ever* produce float overflow, but this would produce NaNs too
//ASSERT(maxDist < std::numeric_limits<float>::max());
ASSERT(maxDist < std::numeric_limits<float>::max());
// prevent NaN values which can cause BIH intersection to enter infinite loop
if (maxDist < 1e-10f)
return true;
// direction with length of 1
G3D::Plane checkPlane = G3D::Plane((pos2 - pos1)/maxDist,pos1, pos2);
G3D::Ray ray = G3D::Ray::fromOriginAndDirection(pos1, (pos2 - pos1)/maxDist);
Vector3 checkFinite = ray.intersection(checkPlane);
if (!checkFinite.isFinite())
float resultDist = getIntersectionTime(ray, maxDist, true);
if (resultDist < maxDist)
{
ray = G3D::Ray::fromOriginAndDirection(pos1, -((pos2 - pos1)/maxDist));
checkFinite = ray.intersection(checkPlane);
}
if (checkFinite.isFinite())
{
float resultDist = getIntersectionTime(ray, maxDist, true);
if (resultDist >= maxDist)
{
result = true;
}
result = false;
}
return result;
}