From 929591d5672e096f173e144eaaac1819fc10ee7e Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sat, 10 Aug 2024 22:45:23 +0200 Subject: [PATCH] Recast: make classifyOffMeshPoint common Will be used once jump links are generated between neighbor tiles. --- .../Detour/Source/DetourNavMeshBuilder.cpp | 32 ++----------------- .../recast/Shared/Include/SharedCommon.h | 2 ++ .../recast/Shared/Source/SharedCommon.cpp | 28 ++++++++++++++++ 3 files changed, 32 insertions(+), 30 deletions(-) diff --git a/src/thirdparty/recast/Detour/Source/DetourNavMeshBuilder.cpp b/src/thirdparty/recast/Detour/Source/DetourNavMeshBuilder.cpp index 1835ba45..4b578be2 100644 --- a/src/thirdparty/recast/Detour/Source/DetourNavMeshBuilder.cpp +++ b/src/thirdparty/recast/Detour/Source/DetourNavMeshBuilder.cpp @@ -236,34 +236,6 @@ static int createBVTree(dtNavMeshCreateParams* params, dtBVNode* nodes, int /*nn return curNode; } -static unsigned char classifyOffMeshPoint(const float* pt, const float* bmin, const float* bmax) -{ - static const unsigned char XP = 1<<0; - static const unsigned char ZP = 1<<1; - static const unsigned char XM = 1<<2; - static const unsigned char ZM = 1<<3; - - unsigned char outcode = 0; - outcode |= (pt[0] >= bmax[0]) ? XP : 0; - outcode |= (pt[1] >= bmax[1]) ? ZP : 0; - outcode |= (pt[0] < bmin[0]) ? XM : 0; - outcode |= (pt[1] < bmin[1]) ? ZM : 0; - - switch (outcode) - { - case XP: return 0; - case XP|ZP: return 1; - case ZP: return 2; - case XM|ZP: return 3; - case XM: return 4; - case XM|ZM: return 5; - case ZM: return 6; - case XP|ZM: return 7; - }; - - return 0xff; -} - static void setPolyGroupsTraversalReachability(int* const tableData, const int numPolyGroups, const unsigned short polyGroup1, const unsigned short polyGroup2, const bool isReachable) { @@ -673,8 +645,8 @@ bool dtCreateNavMeshData(dtNavMeshCreateParams* params, unsigned char** outData, { const float* p0 = ¶ms->offMeshConVerts[(i*2+0)*3]; const float* p1 = ¶ms->offMeshConVerts[(i*2+1)*3]; - offMeshConClass[i*2+0] = classifyOffMeshPoint(p0, bmin, bmax); - offMeshConClass[i*2+1] = classifyOffMeshPoint(p1, bmin, bmax); + offMeshConClass[i*2+0] = rdClassifyPointOutsideBounds(p0, bmin, bmax); + offMeshConClass[i*2+1] = rdClassifyPointOutsideBounds(p1, bmin, bmax); // Zero out off-mesh start positions which are not even potentially touching the mesh. if (offMeshConClass[i*2+0] == 0xff) diff --git a/src/thirdparty/recast/Shared/Include/SharedCommon.h b/src/thirdparty/recast/Shared/Include/SharedCommon.h index b6c23cbf..0b9fbba3 100644 --- a/src/thirdparty/recast/Shared/Include/SharedCommon.h +++ b/src/thirdparty/recast/Shared/Include/SharedCommon.h @@ -432,6 +432,8 @@ bool rdIntersectSegSeg2D(const float* ap, const float* aq, float rdDistancePtLine2d(const float* pt, const float* p, const float* q); +unsigned char rdClassifyPointOutsideBounds(const float* pt, const float* bmin, const float* bmax); + /// Determines if the specified point is inside the convex polygon on the xy-plane. /// @param[in] pt The point to check. [(x, y, z)] /// @param[in] verts The polygon vertices. [(x, y, z) * @p nverts] diff --git a/src/thirdparty/recast/Shared/Source/SharedCommon.cpp b/src/thirdparty/recast/Shared/Source/SharedCommon.cpp index 91db739a..87211900 100644 --- a/src/thirdparty/recast/Shared/Source/SharedCommon.cpp +++ b/src/thirdparty/recast/Shared/Source/SharedCommon.cpp @@ -408,3 +408,31 @@ float rdDistancePtLine2d(const float* pt, const float* p, const float* q) dy = p[1] + t * pqy - pt[1]; return dx * dx + dy * dy; } + +static const unsigned char XP = 1 << 0; +static const unsigned char ZP = 1 << 1; +static const unsigned char XM = 1 << 2; +static const unsigned char ZM = 1 << 3; + +unsigned char rdClassifyPointOutsideBounds(const float* pt, const float* bmin, const float* bmax) +{ + unsigned char outcode = 0; + outcode |= (pt[0] >= bmax[0]) ? XP : 0; + outcode |= (pt[1] >= bmax[1]) ? ZP : 0; + outcode |= (pt[0] < bmin[0]) ? XM : 0; + outcode |= (pt[1] < bmin[1]) ? ZM : 0; + + switch (outcode) + { + case XP: return 0; + case XP|ZP: return 1; + case ZP: return 2; + case XM|ZP: return 3; + case XM: return 4; + case XM|ZM: return 5; + case ZM: return 6; + case XP|ZM: return 7; + }; + + return 0xff; +}