From 61e7b7a443c8aeaed130dd26a27d4b9d6281d3a0 Mon Sep 17 00:00:00 2001 From: ikpil Date: Sun, 12 May 2024 00:25:53 +0900 Subject: [PATCH] update RandomPointInConvexPoly() --- src/DotRecast.Detour/DtNavMeshQuery.cs | 12 ++++++------ src/DotRecast.Detour/DtUtils.cs | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/DotRecast.Detour/DtNavMeshQuery.cs b/src/DotRecast.Detour/DtNavMeshQuery.cs index 55dad90..8ef9844 100644 --- a/src/DotRecast.Detour/DtNavMeshQuery.cs +++ b/src/DotRecast.Detour/DtNavMeshQuery.cs @@ -68,8 +68,8 @@ namespace DotRecast.Detour float tsum = 0.0f; for (int i = 0; i < m_nav.GetMaxTiles(); i++) { - DtMeshTile mt = m_nav.GetTile(i); - if (mt == null || mt.data == null || mt.data.header == null) + DtMeshTile t = m_nav.GetTile(i); + if (t == null || t.data == null || t.data.header == null) { continue; } @@ -80,7 +80,7 @@ namespace DotRecast.Detour float u = frand.Next(); if (u * tsum <= area) { - tile = mt; + tile = t; } } @@ -146,9 +146,9 @@ namespace DotRecast.Detour } float s = frand.Next(); - float t = frand.Next(); + float t0 = frand.Next(); - var pt = DtUtils.RandomPointInConvexPoly(verts, poly.vertCount, areas, s, t); + DtUtils.RandomPointInConvexPoly(verts, poly.vertCount, areas, s, t0, out var pt); ClosestPointOnPoly(polyRef, pt, out var closest, out var _); randomRef = polyRef; @@ -387,7 +387,7 @@ namespace DotRecast.Detour float t = frand.Next(); Span areas = stackalloc float[randomPolyVerts.Length / 3]; - RcVec3f pt = DtUtils.RandomPointInConvexPoly(randomPolyVerts, randomPolyVerts.Length / 3, areas, s, t); + DtUtils.RandomPointInConvexPoly(randomPolyVerts, randomPolyVerts.Length / 3, areas, s, t, out var pt); ClosestPointOnPoly(randomPolyRef, pt, out var closest, out var _); randomRef = randomPolyRef; diff --git a/src/DotRecast.Detour/DtUtils.cs b/src/DotRecast.Detour/DtUtils.cs index e5c2878..098116c 100644 --- a/src/DotRecast.Detour/DtUtils.cs +++ b/src/DotRecast.Detour/DtUtils.cs @@ -165,7 +165,7 @@ namespace DotRecast.Detour // Returns a random point in a convex polygon. // Adapted from Graphics Gems article. - public static RcVec3f RandomPointInConvexPoly(Span pts, int npts, Span areas, float s, float t) + public static void RandomPointInConvexPoly(Span pts, int npts, Span areas, float s, float t, out RcVec3f @out) { // Calc triangle araes float areasum = 0.0f; @@ -202,7 +202,7 @@ namespace DotRecast.Detour int pb = (tri - 1) * 3; int pc = tri * 3; - return new RcVec3f() + @out = new RcVec3f() { X = a * pts[pa] + b * pts[pb] + c * pts[pc], Y = a * pts[pa + 1] + b * pts[pb + 1] + c * pts[pc + 1],