Recast: deduplicate AABB intersection test in CrowdTool

This commit is contained in:
Kawe Mazidjatari 2024-09-20 14:58:22 +02:00
parent 4640a81d09
commit 0722def4d8

View File

@ -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)
{