From b37a77d54775b98b9e772c84b6731d40c61b48d8 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sat, 21 Sep 2024 12:26:34 +0200 Subject: [PATCH] Recast: enforce consistency in intersection code Some code uses different timing bounds. Enforce consistency between all code utilizing this. --- src/naveditor/CrowdTool.cpp | 2 +- src/naveditor/Editor_TempObstacles.cpp | 2 +- src/thirdparty/recast/Shared/Source/SharedCommon.cpp | 11 +++++++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/naveditor/CrowdTool.cpp b/src/naveditor/CrowdTool.cpp index dba5e317..f7e27e12 100644 --- a/src/naveditor/CrowdTool.cpp +++ b/src/naveditor/CrowdTool.cpp @@ -758,7 +758,7 @@ int CrowdToolState::hitTestAgents(const float* s, const float* p) dtCrowd* crowd = m_editor->getCrowd(); int isel = -1; - float tsel = FLT_MAX; + float tsel = 1; for (int i = 0; i < crowd->getAgentCount(); ++i) { diff --git a/src/naveditor/Editor_TempObstacles.cpp b/src/naveditor/Editor_TempObstacles.cpp index ad7ad9e7..66d296e1 100644 --- a/src/naveditor/Editor_TempObstacles.cpp +++ b/src/naveditor/Editor_TempObstacles.cpp @@ -562,7 +562,7 @@ void drawDetailOverlay(const dtTileCache* tc, const int tx, const int ty, double dtObstacleRef hitTestObstacle(const dtTileCache* tc, const float* sp, const float* sq) { - float tmin = FLT_MAX; + float tmin = 1; const dtTileCacheObstacle* obmin = 0; for (int i = 0; i < tc->getObstacleCount(); ++i) { diff --git a/src/thirdparty/recast/Shared/Source/SharedCommon.cpp b/src/thirdparty/recast/Shared/Source/SharedCommon.cpp index 3cfcaa11..83199209 100644 --- a/src/thirdparty/recast/Shared/Source/SharedCommon.cpp +++ b/src/thirdparty/recast/Shared/Source/SharedCommon.cpp @@ -186,8 +186,8 @@ bool rdIntersectSegmentAABB(const float* sp, const float* sq, { 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) + tmin = 0; // set to 0 to get first hit on line + tmax = 1; // set to max distance ray can travel (for segment) // For all three slabs for (int i = 0; i < 3; i++) @@ -221,6 +221,9 @@ bool rdIntersectSegmentCylinder(const float* sp, const float* sq, const float* p const float radius, const float height, float& tmin, float& tmax) { + tmin = 0; + tmax = 1; + const float cx = position[0]; const float cy = position[1]; const float cz = position[2]; @@ -249,8 +252,8 @@ bool rdIntersectSegmentCylinder(const float* sp, const float* sq, const float* p if (t0 > t1) rdSwap(t0, t1); - tmin = rdMax(0.0f, t0); - tmax = rdMin(1.0f, t1); + tmin = rdMax(tmin, t0); + tmax = rdMin(tmax, t1); if (tmin > tmax) return false; // No intersection in the [tmin, tmax] range