for unity3d

This commit is contained in:
ikpil 2023-07-19 23:28:19 +09:00
parent bbb9c7816f
commit 70dc963563
2 changed files with 32 additions and 17 deletions

View File

@ -324,23 +324,9 @@ public class TestNavmeshTool : IRcTool
randomPoints.Clear(); randomPoints.Clear();
if (m_sposSet && m_startRef != 0 && m_eposSet) if (m_sposSet && m_startRef != 0 && m_eposSet)
{ {
float dx = m_epos.x - m_spos.x; var points = new List<RcVec3f>();
float dz = m_epos.z - m_spos.z; _impl.FindRandomPointAroundCircle(m_startRef, m_spos, m_epos, m_filter, option.constrainByCircle, 500, ref points);
float dist = (float)Math.Sqrt(dx * dx + dz * dz); randomPoints.AddRange(points);
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);
}
}
} }
} }
} }

View File

@ -291,5 +291,34 @@ namespace DotRecast.Recast.DemoTool.Tools
var navQuery = _sample.GetNavMeshQuery(); var navQuery = _sample.GetNavMeshQuery();
return navQuery.FindPolysAroundShape(startRef, queryPoly, filter, ref resultRef, ref resultParent, ref costs); 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<RcVec3f> 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;
}
} }
} }