diff --git a/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs b/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs index 2d7cdea..13ba882 100644 --- a/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs @@ -324,23 +324,9 @@ public class TestNavmeshTool : IRcTool randomPoints.Clear(); if (m_sposSet && m_startRef != 0 && m_eposSet) { - float dx = m_epos.x - m_spos.x; - float dz = m_epos.z - m_spos.z; - float dist = (float)Math.Sqrt(dx * dx + dz * dz); - IPolygonByCircleConstraint constraint = option.constrainByCircle - ? StrictPolygonByCircleConstraint.Strict - : NoOpPolygonByCircleConstraint.Noop; - - var frand = new FRand(); - for (int i = 0; i < 200; i++) - { - var status = m_navQuery.FindRandomPointAroundCircle(m_startRef, m_spos, dist, m_filter, frand, constraint, - out var randomRef, out var randomPt); - if (status.Succeeded()) - { - randomPoints.Add(randomPt); - } - } + var points = new List(); + _impl.FindRandomPointAroundCircle(m_startRef, m_spos, m_epos, m_filter, option.constrainByCircle, 500, ref points); + randomPoints.AddRange(points); } } } diff --git a/src/DotRecast.Recast.DemoTool/Tools/TestNavmeshToolImpl.cs b/src/DotRecast.Recast.DemoTool/Tools/TestNavmeshToolImpl.cs index c670ba1..4c012a6 100644 --- a/src/DotRecast.Recast.DemoTool/Tools/TestNavmeshToolImpl.cs +++ b/src/DotRecast.Recast.DemoTool/Tools/TestNavmeshToolImpl.cs @@ -291,5 +291,34 @@ namespace DotRecast.Recast.DemoTool.Tools var navQuery = _sample.GetNavMeshQuery(); return navQuery.FindPolysAroundShape(startRef, queryPoly, filter, ref resultRef, ref resultParent, ref costs); } + + public DtStatus FindRandomPointAroundCircle(long startRef, RcVec3f spos, RcVec3f epos, IDtQueryFilter filter, bool constrainByCircle, int count, ref List points) + { + float dx = epos.x - spos.x; + float dz = epos.z - spos.z; + float dist = (float)Math.Sqrt(dx * dx + dz * dz); + + IPolygonByCircleConstraint constraint = constrainByCircle + ? StrictPolygonByCircleConstraint.Strict + : NoOpPolygonByCircleConstraint.Noop; + + var frand = new FRand(); + var navQuery = _sample.GetNavMeshQuery(); + + int prevCnt = points.Count; + + while (0 < count && points.Count < prevCnt + count) + { + var status = navQuery.FindRandomPointAroundCircle(startRef, spos, dist, filter, frand, constraint, + out var randomRef, out var randomPt); + + if (status.Succeeded()) + { + points.Add(randomPt); + } + } + + return DtStatus.DT_SUCCSESS; + } } } \ No newline at end of file