mirror of
https://github.com/recastnavigation/recastnavigation.git
synced 2026-10-31 04:55:48 +00:00
Merge branch 'main' into release-2.0
# Conflicts: # Recast/Include/Recast.h # Recast/Source/Recast.cpp # RecastDemo/Include/Sample.h # RecastDemo/Source/Sample.cpp
This commit is contained in:
@@ -117,6 +117,11 @@ void dtFreeNavMeshQuery(dtNavMeshQuery* navmesh)
|
||||
dtFree(navmesh);
|
||||
}
|
||||
|
||||
dtPolyQuery::~dtPolyQuery()
|
||||
{
|
||||
// Defined out of line to fix the weak v-tables warning
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// @class dtNavMeshQuery
|
||||
@@ -222,7 +227,10 @@ dtStatus dtNavMeshQuery::findRandomPoint(const dtQueryFilter* filter, float (*fr
|
||||
dtPolyRef* randomRef, float* randomPt) const
|
||||
{
|
||||
dtAssert(m_nav);
|
||||
|
||||
|
||||
if (!filter || !frand || !randomRef || !randomPt)
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
|
||||
// Randomly pick one tile. Assume that all tiles cover roughly the same area.
|
||||
const dtMeshTile* tile = 0;
|
||||
float tsum = 0.0f;
|
||||
@@ -298,11 +306,7 @@ dtStatus dtNavMeshQuery::findRandomPoint(const dtQueryFilter* filter, float (*fr
|
||||
float pt[3];
|
||||
dtRandomPointInConvexPoly(verts, poly->vertCount, areas, s, t, pt);
|
||||
|
||||
float h = 0.0f;
|
||||
dtStatus status = getPolyHeight(polyRef, pt, &h);
|
||||
if (dtStatusFailed(status))
|
||||
return status;
|
||||
pt[1] = h;
|
||||
closestPointOnPoly(polyRef, pt, pt, NULL);
|
||||
|
||||
dtVcopy(randomPt, pt);
|
||||
*randomRef = polyRef;
|
||||
@@ -319,8 +323,13 @@ dtStatus dtNavMeshQuery::findRandomPointAroundCircle(dtPolyRef startRef, const f
|
||||
dtAssert(m_openList);
|
||||
|
||||
// Validate input
|
||||
if (!startRef || !m_nav->isValidPolyRef(startRef))
|
||||
if (!m_nav->isValidPolyRef(startRef) ||
|
||||
!centerPos || !dtVisfinite(centerPos) ||
|
||||
maxRadius < 0 || !dtMathIsfinite(maxRadius) ||
|
||||
!filter || !frand || !randomRef || !randomPt)
|
||||
{
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
}
|
||||
|
||||
const dtMeshTile* startTile = 0;
|
||||
const dtPoly* startPoly = 0;
|
||||
@@ -480,16 +489,12 @@ dtStatus dtNavMeshQuery::findRandomPointAroundCircle(dtPolyRef startRef, const f
|
||||
float pt[3];
|
||||
dtRandomPointInConvexPoly(verts, randomPoly->vertCount, areas, s, t, pt);
|
||||
|
||||
float h = 0.0f;
|
||||
dtStatus stat = getPolyHeight(randomPolyRef, pt, &h);
|
||||
if (dtStatusFailed(status))
|
||||
return stat;
|
||||
pt[1] = h;
|
||||
closestPointOnPoly(randomPolyRef, pt, pt, NULL);
|
||||
|
||||
dtVcopy(randomPt, pt);
|
||||
*randomRef = randomPolyRef;
|
||||
|
||||
return DT_SUCCESS;
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@@ -506,85 +511,14 @@ dtStatus dtNavMeshQuery::findRandomPointAroundCircle(dtPolyRef startRef, const f
|
||||
dtStatus dtNavMeshQuery::closestPointOnPoly(dtPolyRef ref, const float* pos, float* closest, bool* posOverPoly) const
|
||||
{
|
||||
dtAssert(m_nav);
|
||||
const dtMeshTile* tile = 0;
|
||||
const dtPoly* poly = 0;
|
||||
if (dtStatusFailed(m_nav->getTileAndPolyByRef(ref, &tile, &poly)))
|
||||
if (!m_nav->isValidPolyRef(ref) ||
|
||||
!pos || !dtVisfinite(pos) ||
|
||||
!closest)
|
||||
{
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
if (!tile)
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
|
||||
// Off-mesh connections don't have detail polygons.
|
||||
if (poly->getType() == DT_POLYTYPE_OFFMESH_CONNECTION)
|
||||
{
|
||||
const float* v0 = &tile->verts[poly->verts[0]*3];
|
||||
const float* v1 = &tile->verts[poly->verts[1]*3];
|
||||
const float d0 = dtVdist(pos, v0);
|
||||
const float d1 = dtVdist(pos, v1);
|
||||
const float u = d0 / (d0+d1);
|
||||
dtVlerp(closest, v0, v1, u);
|
||||
if (posOverPoly)
|
||||
*posOverPoly = false;
|
||||
return DT_SUCCESS;
|
||||
}
|
||||
|
||||
const unsigned int ip = (unsigned int)(poly - tile->polys);
|
||||
const dtPolyDetail* pd = &tile->detailMeshes[ip];
|
||||
|
||||
// Clamp point to be inside the polygon.
|
||||
float verts[DT_VERTS_PER_POLYGON*3];
|
||||
float edged[DT_VERTS_PER_POLYGON];
|
||||
float edget[DT_VERTS_PER_POLYGON];
|
||||
const int nv = poly->vertCount;
|
||||
for (int i = 0; i < nv; ++i)
|
||||
dtVcopy(&verts[i*3], &tile->verts[poly->verts[i]*3]);
|
||||
|
||||
dtVcopy(closest, pos);
|
||||
if (!dtDistancePtPolyEdgesSqr(pos, verts, nv, edged, edget))
|
||||
{
|
||||
// Point is outside the polygon, dtClamp to nearest edge.
|
||||
float dmin = edged[0];
|
||||
int imin = 0;
|
||||
for (int i = 1; i < nv; ++i)
|
||||
{
|
||||
if (edged[i] < dmin)
|
||||
{
|
||||
dmin = edged[i];
|
||||
imin = i;
|
||||
}
|
||||
}
|
||||
const float* va = &verts[imin*3];
|
||||
const float* vb = &verts[((imin+1)%nv)*3];
|
||||
dtVlerp(closest, va, vb, edget[imin]);
|
||||
|
||||
if (posOverPoly)
|
||||
*posOverPoly = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (posOverPoly)
|
||||
*posOverPoly = true;
|
||||
}
|
||||
|
||||
// Find height at the location.
|
||||
for (int j = 0; j < pd->triCount; ++j)
|
||||
{
|
||||
const unsigned char* t = &tile->detailTris[(pd->triBase+j)*4];
|
||||
const float* v[3];
|
||||
for (int k = 0; k < 3; ++k)
|
||||
{
|
||||
if (t[k] < poly->vertCount)
|
||||
v[k] = &tile->verts[poly->verts[t[k]]*3];
|
||||
else
|
||||
v[k] = &tile->detailVerts[(pd->vertBase+(t[k]-poly->vertCount))*3];
|
||||
}
|
||||
float h;
|
||||
if (dtClosestHeightPointTriangle(closest, v[0], v[1], v[2], h))
|
||||
{
|
||||
closest[1] = h;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
m_nav->closestPointOnPoly(ref, pos, closest, posOverPoly);
|
||||
return DT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -607,6 +541,9 @@ dtStatus dtNavMeshQuery::closestPointOnPolyBoundary(dtPolyRef ref, const float*
|
||||
const dtPoly* poly = 0;
|
||||
if (dtStatusFailed(m_nav->getTileAndPolyByRef(ref, &tile, &poly)))
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
|
||||
if (!pos || !dtVisfinite(pos) || !closest)
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
|
||||
// Collect vertices.
|
||||
float verts[DT_VERTS_PER_POLYGON*3];
|
||||
@@ -648,7 +585,7 @@ dtStatus dtNavMeshQuery::closestPointOnPolyBoundary(dtPolyRef ref, const float*
|
||||
|
||||
/// @par
|
||||
///
|
||||
/// Will return #DT_FAILURE if the provided position is outside the xz-bounds
|
||||
/// Will return #DT_FAILURE | DT_INVALID_PARAM if the provided position is outside the xz-bounds
|
||||
/// of the polygon.
|
||||
///
|
||||
dtStatus dtNavMeshQuery::getPolyHeight(dtPolyRef ref, const float* pos, float* height) const
|
||||
@@ -659,44 +596,28 @@ dtStatus dtNavMeshQuery::getPolyHeight(dtPolyRef ref, const float* pos, float* h
|
||||
const dtPoly* poly = 0;
|
||||
if (dtStatusFailed(m_nav->getTileAndPolyByRef(ref, &tile, &poly)))
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
|
||||
|
||||
if (!pos || !dtVisfinite2D(pos))
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
|
||||
// We used to return success for offmesh connections, but the
|
||||
// getPolyHeight in DetourNavMesh does not do this, so special
|
||||
// case it here.
|
||||
if (poly->getType() == DT_POLYTYPE_OFFMESH_CONNECTION)
|
||||
{
|
||||
const float* v0 = &tile->verts[poly->verts[0]*3];
|
||||
const float* v1 = &tile->verts[poly->verts[1]*3];
|
||||
const float d0 = dtVdist2D(pos, v0);
|
||||
const float d1 = dtVdist2D(pos, v1);
|
||||
const float u = d0 / (d0+d1);
|
||||
float t;
|
||||
dtDistancePtSegSqr2D(pos, v0, v1, t);
|
||||
if (height)
|
||||
*height = v0[1] + (v1[1] - v0[1]) * u;
|
||||
*height = v0[1] + (v1[1] - v0[1])*t;
|
||||
|
||||
return DT_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
const unsigned int ip = (unsigned int)(poly - tile->polys);
|
||||
const dtPolyDetail* pd = &tile->detailMeshes[ip];
|
||||
for (int j = 0; j < pd->triCount; ++j)
|
||||
{
|
||||
const unsigned char* t = &tile->detailTris[(pd->triBase+j)*4];
|
||||
const float* v[3];
|
||||
for (int k = 0; k < 3; ++k)
|
||||
{
|
||||
if (t[k] < poly->vertCount)
|
||||
v[k] = &tile->verts[poly->verts[t[k]]*3];
|
||||
else
|
||||
v[k] = &tile->detailVerts[(pd->vertBase+(t[k]-poly->vertCount))*3];
|
||||
}
|
||||
float h;
|
||||
if (dtClosestHeightPointTriangle(pos, v[0], v[1], v[2], h))
|
||||
{
|
||||
if (height)
|
||||
*height = h;
|
||||
return DT_SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
|
||||
return m_nav->getPolyHeight(tile, poly, pos, height)
|
||||
? DT_SUCCESS
|
||||
: DT_FAILURE | DT_INVALID_PARAM;
|
||||
}
|
||||
|
||||
class dtFindNearestPolyQuery : public dtPolyQuery
|
||||
@@ -706,15 +627,19 @@ class dtFindNearestPolyQuery : public dtPolyQuery
|
||||
float m_nearestDistanceSqr;
|
||||
dtPolyRef m_nearestRef;
|
||||
float m_nearestPoint[3];
|
||||
bool m_overPoly;
|
||||
|
||||
public:
|
||||
dtFindNearestPolyQuery(const dtNavMeshQuery* query, const float* center)
|
||||
: m_query(query), m_center(center), m_nearestDistanceSqr(FLT_MAX), m_nearestRef(0), m_nearestPoint()
|
||||
: m_query(query), m_center(center), m_nearestDistanceSqr(FLT_MAX), m_nearestRef(0), m_nearestPoint(), m_overPoly(false)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~dtFindNearestPolyQuery();
|
||||
|
||||
dtPolyRef nearestRef() const { return m_nearestRef; }
|
||||
const float* nearestPoint() const { return m_nearestPoint; }
|
||||
bool isOverPoly() const { return m_overPoly; }
|
||||
|
||||
void process(const dtMeshTile* tile, dtPoly** polys, dtPolyRef* refs, int count)
|
||||
{
|
||||
@@ -748,29 +673,46 @@ public:
|
||||
|
||||
m_nearestDistanceSqr = d;
|
||||
m_nearestRef = ref;
|
||||
m_overPoly = posOverPoly;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
dtFindNearestPolyQuery::~dtFindNearestPolyQuery()
|
||||
{
|
||||
// Defined out of line to fix the weak v-tables warning
|
||||
}
|
||||
|
||||
/// @par
|
||||
///
|
||||
/// @note If the search box does not intersect any polygons the search will
|
||||
/// return #DT_SUCCESS, but @p nearestRef will be zero. So if in doubt, check
|
||||
/// @p nearestRef before using @p nearestPt.
|
||||
///
|
||||
dtStatus dtNavMeshQuery::findNearestPoly(const float* center, const float* extents,
|
||||
dtStatus dtNavMeshQuery::findNearestPoly(const float* center, const float* halfExtents,
|
||||
const dtQueryFilter* filter,
|
||||
dtPolyRef* nearestRef, float* nearestPt) const
|
||||
{
|
||||
return findNearestPoly(center, halfExtents, filter, nearestRef, nearestPt, NULL);
|
||||
}
|
||||
|
||||
// If center and nearestPt point to an equal position, isOverPoly will be true;
|
||||
// however there's also a special case of climb height inside the polygon (see dtFindNearestPolyQuery)
|
||||
dtStatus dtNavMeshQuery::findNearestPoly(const float* center, const float* halfExtents,
|
||||
const dtQueryFilter* filter,
|
||||
dtPolyRef* nearestRef, float* nearestPt, bool* isOverPoly) const
|
||||
{
|
||||
dtAssert(m_nav);
|
||||
|
||||
if (!nearestRef)
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
|
||||
// queryPolygons below will check rest of params
|
||||
|
||||
dtFindNearestPolyQuery query(this, center);
|
||||
|
||||
dtStatus status = queryPolygons(center, extents, filter, &query);
|
||||
dtStatus status = queryPolygons(center, halfExtents, filter, &query);
|
||||
if (dtStatusFailed(status))
|
||||
return status;
|
||||
|
||||
@@ -778,7 +720,11 @@ dtStatus dtNavMeshQuery::findNearestPoly(const float* center, const float* exten
|
||||
// Only override nearestPt if we actually found a poly so the nearest point
|
||||
// is valid.
|
||||
if (nearestPt && *nearestRef)
|
||||
{
|
||||
dtVcopy(nearestPt, query.nearestPoint());
|
||||
if (isOverPoly)
|
||||
*isOverPoly = query.isOverPoly();
|
||||
}
|
||||
|
||||
return DT_SUCCESS;
|
||||
}
|
||||
@@ -913,6 +859,8 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~dtCollectPolysQuery();
|
||||
|
||||
int numCollected() const { return m_numCollected; }
|
||||
bool overflowed() const { return m_overflow; }
|
||||
|
||||
@@ -934,6 +882,11 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
dtCollectPolysQuery::~dtCollectPolysQuery()
|
||||
{
|
||||
// Defined out of line to fix the weak v-tables warning
|
||||
}
|
||||
|
||||
/// @par
|
||||
///
|
||||
/// If no polygons are found, the function will return #DT_SUCCESS with a
|
||||
@@ -943,7 +896,7 @@ public:
|
||||
/// be filled to capacity. The method of choosing which polygons from the
|
||||
/// full set are included in the partial result set is undefined.
|
||||
///
|
||||
dtStatus dtNavMeshQuery::queryPolygons(const float* center, const float* extents,
|
||||
dtStatus dtNavMeshQuery::queryPolygons(const float* center, const float* halfExtents,
|
||||
const dtQueryFilter* filter,
|
||||
dtPolyRef* polys, int* polyCount, const int maxPolys) const
|
||||
{
|
||||
@@ -952,7 +905,7 @@ dtStatus dtNavMeshQuery::queryPolygons(const float* center, const float* extents
|
||||
|
||||
dtCollectPolysQuery collector(polys, maxPolys);
|
||||
|
||||
dtStatus status = queryPolygons(center, extents, filter, &collector);
|
||||
dtStatus status = queryPolygons(center, halfExtents, filter, &collector);
|
||||
if (dtStatusFailed(status))
|
||||
return status;
|
||||
|
||||
@@ -963,21 +916,25 @@ dtStatus dtNavMeshQuery::queryPolygons(const float* center, const float* extents
|
||||
/// @par
|
||||
///
|
||||
/// The query will be invoked with batches of polygons. Polygons passed
|
||||
/// to the query have bounding boxes that overlap with the center and extents
|
||||
/// to the query have bounding boxes that overlap with the center and halfExtents
|
||||
/// passed to this function. The dtPolyQuery::process function is invoked multiple
|
||||
/// times until all overlapping polygons have been processed.
|
||||
///
|
||||
dtStatus dtNavMeshQuery::queryPolygons(const float* center, const float* extents,
|
||||
dtStatus dtNavMeshQuery::queryPolygons(const float* center, const float* halfExtents,
|
||||
const dtQueryFilter* filter, dtPolyQuery* query) const
|
||||
{
|
||||
dtAssert(m_nav);
|
||||
|
||||
if (!center || !extents || !filter || !query)
|
||||
if (!center || !dtVisfinite(center) ||
|
||||
!halfExtents || !dtVisfinite(halfExtents) ||
|
||||
!filter || !query)
|
||||
{
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
}
|
||||
|
||||
float bmin[3], bmax[3];
|
||||
dtVsub(bmin, center, extents);
|
||||
dtVadd(bmax, center, extents);
|
||||
dtVsub(bmin, center, halfExtents);
|
||||
dtVadd(bmax, center, halfExtents);
|
||||
|
||||
// Find tiles the query touches.
|
||||
int minx, miny, maxx, maxy;
|
||||
@@ -1021,14 +978,20 @@ dtStatus dtNavMeshQuery::findPath(dtPolyRef startRef, dtPolyRef endRef,
|
||||
dtAssert(m_nav);
|
||||
dtAssert(m_nodePool);
|
||||
dtAssert(m_openList);
|
||||
|
||||
if (pathCount)
|
||||
*pathCount = 0;
|
||||
|
||||
if (!pathCount)
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
|
||||
*pathCount = 0;
|
||||
|
||||
// Validate input
|
||||
if (!m_nav->isValidPolyRef(startRef) || !m_nav->isValidPolyRef(endRef) ||
|
||||
!startPos || !endPos || !filter || maxPath <= 0 || !path || !pathCount)
|
||||
!startPos || !dtVisfinite(startPos) ||
|
||||
!endPos || !dtVisfinite(endPos) ||
|
||||
!filter || !path || maxPath <= 0)
|
||||
{
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (startRef == endRef)
|
||||
{
|
||||
@@ -1263,18 +1226,21 @@ dtStatus dtNavMeshQuery::initSlicedFindPath(dtPolyRef startRef, dtPolyRef endRef
|
||||
m_query.status = DT_FAILURE;
|
||||
m_query.startRef = startRef;
|
||||
m_query.endRef = endRef;
|
||||
dtVcopy(m_query.startPos, startPos);
|
||||
dtVcopy(m_query.endPos, endPos);
|
||||
if (startPos)
|
||||
dtVcopy(m_query.startPos, startPos);
|
||||
if (endPos)
|
||||
dtVcopy(m_query.endPos, endPos);
|
||||
m_query.filter = filter;
|
||||
m_query.options = options;
|
||||
m_query.raycastLimitSqr = FLT_MAX;
|
||||
|
||||
if (!startRef || !endRef)
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
|
||||
// Validate input
|
||||
if (!m_nav->isValidPolyRef(startRef) || !m_nav->isValidPolyRef(endRef))
|
||||
if (!m_nav->isValidPolyRef(startRef) || !m_nav->isValidPolyRef(endRef) ||
|
||||
!startPos || !dtVisfinite(startPos) ||
|
||||
!endPos || !dtVisfinite(endPos) || !filter)
|
||||
{
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
}
|
||||
|
||||
// trade quality with performance?
|
||||
if (options & DT_FINDPATH_ANY_ANGLE)
|
||||
@@ -1530,7 +1496,13 @@ dtStatus dtNavMeshQuery::updateSlicedFindPath(const int maxIter, int* doneIters)
|
||||
|
||||
dtStatus dtNavMeshQuery::finalizeSlicedFindPath(dtPolyRef* path, int* pathCount, const int maxPath)
|
||||
{
|
||||
if (!pathCount)
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
|
||||
*pathCount = 0;
|
||||
|
||||
if (!path || maxPath <= 0)
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
|
||||
if (dtStatusFailed(m_query.status))
|
||||
{
|
||||
@@ -1615,12 +1587,13 @@ dtStatus dtNavMeshQuery::finalizeSlicedFindPath(dtPolyRef* path, int* pathCount,
|
||||
dtStatus dtNavMeshQuery::finalizeSlicedFindPathPartial(const dtPolyRef* existing, const int existingSize,
|
||||
dtPolyRef* path, int* pathCount, const int maxPath)
|
||||
{
|
||||
if (!pathCount)
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
|
||||
*pathCount = 0;
|
||||
|
||||
if (existingSize == 0)
|
||||
{
|
||||
return DT_FAILURE;
|
||||
}
|
||||
|
||||
if (!existing || existingSize <= 0 || !path || !pathCount || maxPath <= 0)
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
|
||||
if (dtStatusFailed(m_query.status))
|
||||
{
|
||||
@@ -1823,14 +1796,19 @@ dtStatus dtNavMeshQuery::findStraightPath(const float* startPos, const float* en
|
||||
int* straightPathCount, const int maxStraightPath, const int options) const
|
||||
{
|
||||
dtAssert(m_nav);
|
||||
|
||||
|
||||
if (!straightPathCount)
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
|
||||
*straightPathCount = 0;
|
||||
|
||||
if (!maxStraightPath)
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
|
||||
if (!path[0])
|
||||
|
||||
if (!startPos || !dtVisfinite(startPos) ||
|
||||
!endPos || !dtVisfinite(endPos) ||
|
||||
!path || pathSize <= 0 || !path[0] ||
|
||||
maxStraightPath <= 0)
|
||||
{
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
}
|
||||
|
||||
dtStatus stat = 0;
|
||||
|
||||
@@ -2070,13 +2048,19 @@ dtStatus dtNavMeshQuery::moveAlongSurface(dtPolyRef startRef, const float* start
|
||||
dtAssert(m_nav);
|
||||
dtAssert(m_tinyNodePool);
|
||||
|
||||
if (!visitedCount)
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
|
||||
*visitedCount = 0;
|
||||
|
||||
// Validate input
|
||||
if (!startRef)
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
if (!m_nav->isValidPolyRef(startRef))
|
||||
|
||||
if (!m_nav->isValidPolyRef(startRef) ||
|
||||
!startPos || !dtVisfinite(startPos) ||
|
||||
!endPos || !dtVisfinite(endPos) ||
|
||||
!filter || !resultPos || !visited ||
|
||||
maxVisitedSize <= 0)
|
||||
{
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
}
|
||||
|
||||
dtStatus status = DT_SUCCESS;
|
||||
|
||||
@@ -2484,16 +2468,23 @@ dtStatus dtNavMeshQuery::raycast(dtPolyRef startRef, const float* startPos, cons
|
||||
dtRaycastHit* hit, dtPolyRef prevRef) const
|
||||
{
|
||||
dtAssert(m_nav);
|
||||
|
||||
|
||||
if (!hit)
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
|
||||
hit->t = 0;
|
||||
hit->pathCount = 0;
|
||||
hit->pathCost = 0;
|
||||
|
||||
// Validate input
|
||||
if (!startRef || !m_nav->isValidPolyRef(startRef))
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
if (prevRef && !m_nav->isValidPolyRef(prevRef))
|
||||
if (!m_nav->isValidPolyRef(startRef) ||
|
||||
!startPos || !dtVisfinite(startPos) ||
|
||||
!endPos || !dtVisfinite(endPos) ||
|
||||
!filter ||
|
||||
(prevRef && !m_nav->isValidPolyRef(prevRef)))
|
||||
{
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
}
|
||||
|
||||
float dir[3], curPos[3], lastPos[3];
|
||||
float verts[DT_VERTS_PER_POLYGON*3+3];
|
||||
@@ -2735,11 +2726,18 @@ dtStatus dtNavMeshQuery::findPolysAroundCircle(dtPolyRef startRef, const float*
|
||||
dtAssert(m_nodePool);
|
||||
dtAssert(m_openList);
|
||||
|
||||
*resultCount = 0;
|
||||
|
||||
// Validate input
|
||||
if (!startRef || !m_nav->isValidPolyRef(startRef))
|
||||
if (!resultCount)
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
|
||||
*resultCount = 0;
|
||||
|
||||
if (!m_nav->isValidPolyRef(startRef) ||
|
||||
!centerPos || !dtVisfinite(centerPos) ||
|
||||
radius < 0 || !dtMathIsfinite(radius) ||
|
||||
!filter || maxResult < 0)
|
||||
{
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
}
|
||||
|
||||
m_nodePool->clear();
|
||||
m_openList->clear();
|
||||
@@ -2901,8 +2899,18 @@ dtStatus dtNavMeshQuery::findPolysAroundShape(dtPolyRef startRef, const float* v
|
||||
dtAssert(m_nav);
|
||||
dtAssert(m_nodePool);
|
||||
dtAssert(m_openList);
|
||||
|
||||
|
||||
if (!resultCount)
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
|
||||
*resultCount = 0;
|
||||
|
||||
if (!m_nav->isValidPolyRef(startRef) ||
|
||||
!verts || nverts < 3 ||
|
||||
!filter || maxResult < 0)
|
||||
{
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
}
|
||||
|
||||
// Validate input
|
||||
if (!startRef || !m_nav->isValidPolyRef(startRef))
|
||||
@@ -3088,13 +3096,20 @@ dtStatus dtNavMeshQuery::findLocalNeighbourhood(dtPolyRef startRef, const float*
|
||||
{
|
||||
dtAssert(m_nav);
|
||||
dtAssert(m_tinyNodePool);
|
||||
|
||||
|
||||
if (!resultCount)
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
|
||||
*resultCount = 0;
|
||||
|
||||
// Validate input
|
||||
if (!startRef || !m_nav->isValidPolyRef(startRef))
|
||||
if (!m_nav->isValidPolyRef(startRef) ||
|
||||
!centerPos || !dtVisfinite(centerPos) ||
|
||||
radius < 0 || !dtMathIsfinite(radius) ||
|
||||
!filter || maxResult < 0)
|
||||
{
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
|
||||
}
|
||||
|
||||
static const int MAX_STACK = 48;
|
||||
dtNode* stack[MAX_STACK];
|
||||
int nstack = 0;
|
||||
@@ -3301,13 +3316,19 @@ dtStatus dtNavMeshQuery::getPolyWallSegments(dtPolyRef ref, const dtQueryFilter*
|
||||
const int maxSegments) const
|
||||
{
|
||||
dtAssert(m_nav);
|
||||
|
||||
if (!segmentCount)
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
|
||||
*segmentCount = 0;
|
||||
|
||||
|
||||
const dtMeshTile* tile = 0;
|
||||
const dtPoly* poly = 0;
|
||||
if (dtStatusFailed(m_nav->getTileAndPolyByRef(ref, &tile, &poly)))
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
|
||||
if (!filter || !segmentVerts || maxSegments < 0)
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
|
||||
int n = 0;
|
||||
static const int MAX_INTERVAL = 16;
|
||||
@@ -3455,8 +3476,13 @@ dtStatus dtNavMeshQuery::findDistanceToWall(dtPolyRef startRef, const float* cen
|
||||
dtAssert(m_openList);
|
||||
|
||||
// Validate input
|
||||
if (!startRef || !m_nav->isValidPolyRef(startRef))
|
||||
if (!m_nav->isValidPolyRef(startRef) ||
|
||||
!centerPos || !dtVisfinite(centerPos) ||
|
||||
maxRadius < 0 || !dtMathIsfinite(maxRadius) ||
|
||||
!filter || !hitDist || !hitPos || !hitNormal)
|
||||
{
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
}
|
||||
|
||||
m_nodePool->clear();
|
||||
m_openList->clear();
|
||||
|
||||
Reference in New Issue
Block a user