From 0722def4d898903b2fe90701c304d79981e0605d Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Fri, 20 Sep 2024 14:58:22 +0200 Subject: [PATCH] Recast: deduplicate AABB intersection test in CrowdTool --- src/naveditor/CrowdTool.cpp | 39 +------------------------------------ 1 file changed, 1 insertion(+), 38 deletions(-) diff --git a/src/naveditor/CrowdTool.cpp b/src/naveditor/CrowdTool.cpp index 38b21da9..dba5e317 100644 --- a/src/naveditor/CrowdTool.cpp +++ b/src/naveditor/CrowdTool.cpp @@ -27,43 +27,6 @@ #include "NavEditor/Include/EditorInterfaces.h" #include "DetourCrowd/Include/DetourCrowdInternal.h" -static bool isectSegAABB(const float* sp, const float* sq, - const float* amin, const float* amax, - float& tmin, float& tmax) -{ - float d[3]; - rdVsub(d, sq, sp); - tmin = 0; // set to -FLT_MAX to get first hit on line - tmax = FLT_MAX; // set to max distance ray can travel (for segment) - - // For all three slabs - for (int i = 0; i < 3; i++) - { - if (fabsf(d[i]) < RD_EPS) - { - // Ray is parallel to slab. No hit if origin not within slab - if (sp[i] < amin[i] || sp[i] > amax[i]) - return false; - } - else - { - // Compute intersection t value of ray with near and far plane of slab - const float ood = 1.0f / d[i]; - float t1 = (amin[i] - sp[i]) * ood; - float t2 = (amax[i] - sp[i]) * ood; - // Make t1 be intersection with near plane, t2 with far plane - if (t1 > t2) rdSwap(t1, t2); - // Compute the intersection of slab intersections intervals - if (t1 > tmin) tmin = t1; - if (t2 < tmax) tmax = t2; - // Exit with no collision as soon as slab intersection becomes empty - if (tmin > tmax) return false; - } - } - - return true; -} - static void getAgentBounds(const dtCrowdAgent* ag, float* bmin, float* bmax) { const float* p = ag->npos; @@ -804,7 +767,7 @@ int CrowdToolState::hitTestAgents(const float* s, const float* p) float bmin[3], bmax[3]; getAgentBounds(ag, bmin, bmax); float tmin, tmax; - if (isectSegAABB(s, p, bmin,bmax, tmin, tmax)) + if (rdIntersectSegmentAABB(s, p, bmin,bmax, tmin, tmax)) { if (tmin > 0 && tmin < tsel) {