mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-02-21 18:39:40 +00:00
Move duplicated usage patter of dtNavMeshQuery::findNearestPoly into a separate function
This commit is contained in:
parent
d3ab6c972f
commit
a7fe6c7ba1
3 changed files with 19 additions and 27 deletions
|
@ -20,15 +20,7 @@ namespace DetourNavigator
|
||||||
dtQueryFilter queryFilter;
|
dtQueryFilter queryFilter;
|
||||||
queryFilter.setIncludeFlags(includeFlags);
|
queryFilter.setIncludeFlags(includeFlags);
|
||||||
|
|
||||||
dtPolyRef startRef = 0;
|
dtPolyRef startRef = findNearestPolyExpanding(navMeshQuery, queryFilter, start, halfExtents);
|
||||||
for (int i = 0; i < 3; ++i)
|
|
||||||
{
|
|
||||||
const auto status = navMeshQuery.findNearestPoly(start.ptr(), (halfExtents * (1 << i)).ptr(), &queryFilter,
|
|
||||||
&startRef, nullptr);
|
|
||||||
if (!dtStatusFailed(status) && startRef != 0)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (startRef == 0)
|
if (startRef == 0)
|
||||||
return std::optional<osg::Vec3f>();
|
return std::optional<osg::Vec3f>();
|
||||||
|
|
||||||
|
|
|
@ -140,4 +140,17 @@ namespace DetourNavigator
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dtPolyRef findNearestPolyExpanding(const dtNavMeshQuery& query, const dtQueryFilter& filter,
|
||||||
|
const osg::Vec3f& center, const osg::Vec3f& halfExtents)
|
||||||
|
{
|
||||||
|
dtPolyRef ref = 0;
|
||||||
|
for (int i = 0; i < 3; ++i)
|
||||||
|
{
|
||||||
|
const dtStatus status = query.findNearestPoly(center.ptr(), (halfExtents * (1 << i)).ptr(), &filter, &ref, nullptr);
|
||||||
|
if (!dtStatusFailed(status) && ref != 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return ref;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,6 +103,9 @@ namespace DetourNavigator
|
||||||
return dtStatusSucceed(status);
|
return dtStatusSucceed(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dtPolyRef findNearestPolyExpanding(const dtNavMeshQuery& query, const dtQueryFilter& filter,
|
||||||
|
const osg::Vec3f& center, const osg::Vec3f& halfExtents);
|
||||||
|
|
||||||
struct MoveAlongSurfaceResult
|
struct MoveAlongSurfaceResult
|
||||||
{
|
{
|
||||||
osg::Vec3f mResultPos;
|
osg::Vec3f mResultPos;
|
||||||
|
@ -282,27 +285,11 @@ namespace DetourNavigator
|
||||||
queryFilter.setAreaCost(AreaType_pathgrid, areaCosts.mPathgrid);
|
queryFilter.setAreaCost(AreaType_pathgrid, areaCosts.mPathgrid);
|
||||||
queryFilter.setAreaCost(AreaType_ground, areaCosts.mGround);
|
queryFilter.setAreaCost(AreaType_ground, areaCosts.mGround);
|
||||||
|
|
||||||
dtPolyRef startRef = 0;
|
dtPolyRef startRef = findNearestPolyExpanding(navMeshQuery, queryFilter, start, halfExtents);
|
||||||
for (int i = 0; i < 3; ++i)
|
|
||||||
{
|
|
||||||
const auto status = navMeshQuery.findNearestPoly(start.ptr(), (halfExtents * (1 << i)).ptr(), &queryFilter,
|
|
||||||
&startRef, nullptr);
|
|
||||||
if (!dtStatusFailed(status) && startRef != 0)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (startRef == 0)
|
if (startRef == 0)
|
||||||
return Status::StartPolygonNotFound;
|
return Status::StartPolygonNotFound;
|
||||||
|
|
||||||
dtPolyRef endRef = 0;
|
dtPolyRef endRef = findNearestPolyExpanding(navMeshQuery, queryFilter, end, halfExtents);
|
||||||
for (int i = 0; i < 3; ++i)
|
|
||||||
{
|
|
||||||
const auto status = navMeshQuery.findNearestPoly(end.ptr(), (halfExtents * (1 << i)).ptr(), &queryFilter,
|
|
||||||
&endRef, nullptr);
|
|
||||||
if (!dtStatusFailed(status) && endRef != 0)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (endRef == 0)
|
if (endRef == 0)
|
||||||
return Status::EndPolygonNotFound;
|
return Status::EndPolygonNotFound;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue