From eff312acf54b8eddb9ca831d7ebe5554fac94777 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Wed, 10 Jul 2024 20:36:24 +0200 Subject: [PATCH] Recast: fix dtRandomPointInConvexPoly (XZY -> XYZ) Commit 11a827d54805b605a2500b4f6f13b8237bfffffd fixes 'dtNavMeshQuery::findRandomPoint' and 'dtNavMeshQuery::findRandomPointAroundCircle' never returning a poly as the vert indexing was inverted. Although random positions are returned now, they are always either on a tile border, or a poly triangle. This patch fixes the incorrect calculation of triangle area, and output position writing caused by a similar mixup of verts. --- src/thirdparty/recast/Detour/Source/DetourCommon.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/thirdparty/recast/Detour/Source/DetourCommon.cpp b/src/thirdparty/recast/Detour/Source/DetourCommon.cpp index 60bb9774..3f328f56 100644 --- a/src/thirdparty/recast/Detour/Source/DetourCommon.cpp +++ b/src/thirdparty/recast/Detour/Source/DetourCommon.cpp @@ -332,10 +332,10 @@ bool dtOverlapPolyPoly2D(const float* polya, const int npolya, void dtRandomPointInConvexPoly(const float* pts, const int npts, float* areas, const float s, const float t, float* out) { - // Calc triangle araes + // Calc triangle areas float areasum = 0.0f; for (int i = 2; i < npts; i++) { - areas[i] = dtTriArea2D(&pts[0], &pts[(i-1)*3], &pts[i*3]); + areas[i] = dtTriArea2D(&pts[0], &pts[i*3], &pts[(i-1)*3]); areasum += dtMax(0.001f, areas[i]); } // Find sub triangle weighted by area. @@ -360,8 +360,8 @@ void dtRandomPointInConvexPoly(const float* pts, const int npts, float* areas, const float b = (1 - u) * v; const float c = u * v; const float* pa = &pts[0]; - const float* pb = &pts[(tri-1)*3]; - const float* pc = &pts[tri*3]; + const float* pb = &pts[tri*3]; + const float* pc = &pts[(tri-1)*3]; out[0] = a*pa[0] + b*pb[0] + c*pc[0]; out[1] = a*pa[1] + b*pb[1] + c*pc[1];