|
|
|
@ -103,6 +103,9 @@ namespace DetourNavigator
|
|
|
|
|
return dtStatusSucceed(status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dtPolyRef findNearestPolyExpanding(const dtNavMeshQuery& query, const dtQueryFilter& filter,
|
|
|
|
|
const osg::Vec3f& center, const osg::Vec3f& halfExtents);
|
|
|
|
|
|
|
|
|
|
struct MoveAlongSurfaceResult
|
|
|
|
|
{
|
|
|
|
|
osg::Vec3f mResultPos;
|
|
|
|
@ -163,7 +166,7 @@ namespace DetourNavigator
|
|
|
|
|
osg::Vec3f targetPos;
|
|
|
|
|
navMeshQuery.closestPointOnPoly(polygonPath.back(), end.ptr(), targetPos.ptr(), nullptr);
|
|
|
|
|
|
|
|
|
|
const float SLOP = 0.01f;
|
|
|
|
|
constexpr float slop = 0.01f;
|
|
|
|
|
|
|
|
|
|
*out++ = iterPos;
|
|
|
|
|
|
|
|
|
@ -174,7 +177,7 @@ namespace DetourNavigator
|
|
|
|
|
while (!polygonPath.empty() && smoothPathSize < maxSmoothPathSize)
|
|
|
|
|
{
|
|
|
|
|
// Find location to steer towards.
|
|
|
|
|
const auto steerTarget = getSteerTarget(navMeshQuery, iterPos, targetPos, SLOP, polygonPath);
|
|
|
|
|
const auto steerTarget = getSteerTarget(navMeshQuery, iterPos, targetPos, slop, polygonPath);
|
|
|
|
|
|
|
|
|
|
if (!steerTarget)
|
|
|
|
|
break;
|
|
|
|
@ -206,7 +209,7 @@ namespace DetourNavigator
|
|
|
|
|
iterPos.y() = h;
|
|
|
|
|
|
|
|
|
|
// Handle end of path and off-mesh links when close enough.
|
|
|
|
|
if (endOfPath && inRange(iterPos, steerTarget->steerPos, SLOP, 1.0f))
|
|
|
|
|
if (endOfPath && inRange(iterPos, steerTarget->steerPos, slop, 1.0f))
|
|
|
|
|
{
|
|
|
|
|
// Reached end of path.
|
|
|
|
|
iterPos = targetPos;
|
|
|
|
@ -214,7 +217,7 @@ namespace DetourNavigator
|
|
|
|
|
++smoothPathSize;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else if (offMeshConnection && inRange(iterPos, steerTarget->steerPos, SLOP, 1.0f))
|
|
|
|
|
else if (offMeshConnection && inRange(iterPos, steerTarget->steerPos, slop, 1.0f))
|
|
|
|
|
{
|
|
|
|
|
// Advance the path up to and over the off-mesh connection.
|
|
|
|
|
dtPolyRef prevRef = 0;
|
|
|
|
@ -282,29 +285,11 @@ namespace DetourNavigator
|
|
|
|
|
queryFilter.setAreaCost(AreaType_pathgrid, areaCosts.mPathgrid);
|
|
|
|
|
queryFilter.setAreaCost(AreaType_ground, areaCosts.mGround);
|
|
|
|
|
|
|
|
|
|
dtPolyRef startRef = 0;
|
|
|
|
|
osg::Vec3f startPolygonPosition;
|
|
|
|
|
for (int i = 0; i < 3; ++i)
|
|
|
|
|
{
|
|
|
|
|
const auto status = navMeshQuery.findNearestPoly(start.ptr(), (halfExtents * (1 << i)).ptr(), &queryFilter,
|
|
|
|
|
&startRef, startPolygonPosition.ptr());
|
|
|
|
|
if (!dtStatusFailed(status) && startRef != 0)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dtPolyRef startRef = findNearestPolyExpanding(navMeshQuery, queryFilter, start, halfExtents);
|
|
|
|
|
if (startRef == 0)
|
|
|
|
|
return Status::StartPolygonNotFound;
|
|
|
|
|
|
|
|
|
|
dtPolyRef endRef = 0;
|
|
|
|
|
osg::Vec3f endPolygonPosition;
|
|
|
|
|
for (int i = 0; i < 3; ++i)
|
|
|
|
|
{
|
|
|
|
|
const auto status = navMeshQuery.findNearestPoly(end.ptr(), (halfExtents * (1 << i)).ptr(), &queryFilter,
|
|
|
|
|
&endRef, endPolygonPosition.ptr());
|
|
|
|
|
if (!dtStatusFailed(status) && endRef != 0)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dtPolyRef endRef = findNearestPolyExpanding(navMeshQuery, queryFilter, end, halfExtents);
|
|
|
|
|
if (endRef == 0)
|
|
|
|
|
return Status::EndPolygonNotFound;
|
|
|
|
|
|
|
|
|
|