Remove redundant check for y coordinate in inRange function

This commit is contained in:
elsid 2021-06-30 19:58:11 +02:00
parent 83d0db667e
commit a3942a1e0a
No known key found for this signature in database
GPG key ID: B845CB9FEE18AB40
2 changed files with 9 additions and 12 deletions

View file

@ -125,7 +125,7 @@ namespace DetourNavigator
{ {
// Stop at Off-Mesh link or when point is further than slop away. // Stop at Off-Mesh link or when point is further than slop away.
if ((steerPathFlags[ns] & DT_STRAIGHTPATH_OFFMESH_CONNECTION) || if ((steerPathFlags[ns] & DT_STRAIGHTPATH_OFFMESH_CONNECTION) ||
!inRange(Misc::Convert::makeOsgVec3f(&steerPath[ns * 3]), startPos, minTargetDist, 1000.0f)) !inRange(Misc::Convert::makeOsgVec3f(&steerPath[ns * 3]), startPos, minTargetDist))
break; break;
ns++; ns++;
} }

View file

@ -26,10 +26,10 @@ namespace DetourNavigator
{ {
struct Settings; struct Settings;
inline bool inRange(const osg::Vec3f& v1, const osg::Vec3f& v2, const float r, const float h) inline bool inRange(const osg::Vec3f& v1, const osg::Vec3f& v2, const float r)
{ {
const auto d = v2 - v1; const auto d = v2 - v1;
return (d.x() * d.x() + d.z() * d.z()) < r * r && std::abs(d.y()) < h; return (d.x() * d.x() + d.z() * d.z()) < r * r;
} }
std::vector<dtPolyRef> fixupCorridor(const std::vector<dtPolyRef>& path, const std::vector<dtPolyRef>& visited); std::vector<dtPolyRef> fixupCorridor(const std::vector<dtPolyRef>& path, const std::vector<dtPolyRef>& visited);
@ -201,13 +201,8 @@ namespace DetourNavigator
polygonPath = fixupCorridor(polygonPath, result->mVisited); polygonPath = fixupCorridor(polygonPath, result->mVisited);
polygonPath = fixupShortcuts(polygonPath, navMeshQuery); polygonPath = fixupShortcuts(polygonPath, navMeshQuery);
float h = 0;
navMeshQuery.getPolyHeight(polygonPath.front(), result->mResultPos.ptr(), &h);
iterPos = result->mResultPos;
iterPos.y() = h;
// Handle end of path and off-mesh links when close enough. // Handle end of path and off-mesh links when close enough.
if (endOfPath && inRange(iterPos, steerTarget->steerPos, slop, 1.0f)) if (endOfPath && inRange(result->mResultPos, steerTarget->steerPos, slop))
{ {
// Reached end of path. // Reached end of path.
iterPos = targetPos; iterPos = targetPos;
@ -215,7 +210,7 @@ namespace DetourNavigator
++smoothPathSize; ++smoothPathSize;
break; break;
} }
else if (offMeshConnection && inRange(iterPos, steerTarget->steerPos, slop, 1.0f)) else if (offMeshConnection && inRange(result->mResultPos, steerTarget->steerPos, slop))
{ {
// Advance the path up to and over the off-mesh connection. // Advance the path up to and over the off-mesh connection.
dtPolyRef prevRef = 0; dtPolyRef prevRef = 0;
@ -251,14 +246,16 @@ namespace DetourNavigator
// Move position at the other side of the off-mesh link. // Move position at the other side of the off-mesh link.
iterPos = endPos; iterPos = endPos;
const auto height = getPolyHeight(navMeshQuery, polygonPath.front(), iterPos); const auto height = getPolyHeight(navMeshQuery, polygonPath.front(), iterPos);
if (!height) if (!height)
return Status::GetPolyHeightFailed; return Status::GetPolyHeightFailed;
iterPos.y() = *height; iterPos.y() = *height;
} }
} }
navMeshQuery.getPolyHeight(polygonPath.front(), result->mResultPos.ptr(), &iterPos.y());
iterPos.x() = result->mResultPos.x();
iterPos.z() = result->mResultPos.z();
// Store results. // Store results.
*out++ = iterPos; *out++ = iterPos;
++smoothPathSize; ++smoothPathSize;