bool StaticMapTree::isInLineOfSight(const Vector3& pos1, const Vector3& pos2) const { 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()); // prevent NaN values which can cause BIH intersection to enter infinite loop if (maxDist < 1e-10f) return true; // direction with length of 1 G3D::Ray ray = G3D::Ray::fromOriginAndDirection(pos1, (pos2 - pos1)/maxDist); if (getIntersectionTime(ray, maxDist, true)) return false; return true; }
bool StaticMapTree::isInLineOfSight(const Vector3& pos1, const Vector3& pos2) const { bool result = true; float maxDist = (pos2 - pos1).magnitude(); // prevent NaN values which can cause BIH intersection to enter infinite loop if (maxDist < 1e-10f) return true; // direction with length of 1 G3D::Ray ray = G3D::Ray::fromOriginAndDirection(pos1, (pos2 - pos1)/maxDist); float resultDist = getIntersectionTime(ray, maxDist, true); if(resultDist < maxDist) { result = false; } return result; }
bool StaticMapTree::getObjectHitPos(const Vector3& pPos1, const Vector3& pPos2, Vector3& pResultHitPos, float pModifyDist) const { bool result=false; float maxDist = (pPos2 - pPos1).magnitude(); // valid map coords should *never ever* produce float overflow, but this would produce NaNs too if (maxDist >= std::numeric_limits<float>::max()) return false; // prevent NaN values which can cause BIH intersection to enter infinite loop if (maxDist < 1e-10f) { pResultHitPos = pPos2; return false; } Vector3 dir = (pPos2 - pPos1)/maxDist; // direction with length of 1 G3D::Ray ray(pPos1, dir); float dist = maxDist; if (getIntersectionTime(ray, dist, false)) { pResultHitPos = pPos1 + dir * dist; if (pModifyDist < 0) { if ((pResultHitPos - pPos1).magnitude() > -pModifyDist) { pResultHitPos = pResultHitPos + dir*pModifyDist; } else { pResultHitPos = pPos1; } } else { pResultHitPos = pResultHitPos + dir*pModifyDist; } result = true; } else { pResultHitPos = pPos2; result = false; } return result; }
bool StaticMapTree::isInLineOfSight(const Vector3& pos1, const Vector3& pos2, ModelIgnoreFlags ignoreFlag) const { float maxDist = (pos2 - pos1).magnitude(); // return false if distance is over max float, in case of cheater teleporting to the end of the universe if (maxDist == std::numeric_limits<float>::max() || !std::isfinite(maxDist)) return false; // valid map coords should *never ever* produce float overflow, but this would produce NaNs too 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::Ray ray = G3D::Ray::fromOriginAndDirection(pos1, (pos2 - pos1)/maxDist); if (getIntersectionTime(ray, maxDist, true, ignoreFlag)) return false; return true; }
bool StaticMapTree::getObjectHitPos(const Vector3& pPos1, const Vector3& pPos2, Vector3& pResultHitPos, float pModifyDist) const { bool result=false; float maxDist = (pPos2 - pPos1).magnitude(); // prevent NaN values which can cause BIH intersection to enter infinite loop if (maxDist < 1e-10f) { pResultHitPos = pPos2; return false; } Vector3 dir = (pPos2 - pPos1)/maxDist; // direction with length of 1 G3D::Ray ray(pPos1, dir); float dist = getIntersectionTime(ray, maxDist, false); if(dist < maxDist) { pResultHitPos = pPos1 + dir * dist; if(pModifyDist < 0) { if ((pResultHitPos - pPos1).magnitude() > -pModifyDist) { pResultHitPos = pResultHitPos + dir*pModifyDist; } else { pResultHitPos = pPos1; } } else { pResultHitPos = pResultHitPos + dir*pModifyDist; } result = true; } else { pResultHitPos = pPos2; result = false; } return result; }