forked from bit/DotRecastNetSim
refactor: RANDOM_POINTS_IN_CIRCLE
This commit is contained in:
parent
a0a3a24e75
commit
5fd07d1e07
|
@ -63,7 +63,7 @@ public class TestNavmeshSampleTool : ISampleTool
|
||||||
private RcVec3f[] m_queryPoly = new RcVec3f[4];
|
private RcVec3f[] m_queryPoly = new RcVec3f[4];
|
||||||
private List<RcVec3f> m_smoothPath;
|
private List<RcVec3f> m_smoothPath;
|
||||||
private DtStatus m_pathFindStatus = DtStatus.DT_FAILURE;
|
private DtStatus m_pathFindStatus = DtStatus.DT_FAILURE;
|
||||||
private readonly List<RcVec3f> randomPoints = new();
|
private List<RcVec3f> _randomPoints = new();
|
||||||
|
|
||||||
public TestNavmeshSampleTool()
|
public TestNavmeshSampleTool()
|
||||||
{
|
{
|
||||||
|
@ -552,7 +552,7 @@ public class TestNavmeshSampleTool : ISampleTool
|
||||||
dd.DepthMask(false);
|
dd.DepthMask(false);
|
||||||
dd.Begin(POINTS, 4.0f);
|
dd.Begin(POINTS, 4.0f);
|
||||||
int col = DuRGBA(64, 16, 0, 220);
|
int col = DuRGBA(64, 16, 0, 220);
|
||||||
foreach (RcVec3f point in randomPoints)
|
foreach (RcVec3f point in _randomPoints)
|
||||||
{
|
{
|
||||||
dd.Vertex(point.x, point.y + 0.1f, point.z, col);
|
dd.Vertex(point.x, point.y + 0.1f, point.z, col);
|
||||||
}
|
}
|
||||||
|
@ -766,13 +766,7 @@ public class TestNavmeshSampleTool : ISampleTool
|
||||||
}
|
}
|
||||||
else if (_mode == RcTestNavmeshToolMode.RANDOM_POINTS_IN_CIRCLE)
|
else if (_mode == RcTestNavmeshToolMode.RANDOM_POINTS_IN_CIRCLE)
|
||||||
{
|
{
|
||||||
randomPoints.Clear();
|
_tool.FindRandomPointAroundCircle(navQuery, m_startRef, m_endRef, m_spos, m_epos, m_filter, _constrainByCircle, _randomPointCount, ref _randomPoints);
|
||||||
if (m_sposSet && m_startRef != 0 && m_eposSet)
|
|
||||||
{
|
|
||||||
var points = new List<RcVec3f>();
|
|
||||||
_tool.FindRandomPointAroundCircle(navQuery, m_startRef, m_spos, m_epos, m_filter, _constrainByCircle, _randomPointCount, ref points);
|
|
||||||
randomPoints.AddRange(points);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -325,8 +325,14 @@ namespace DotRecast.Recast.Toolset.Tools
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DtStatus FindRandomPointAroundCircle(DtNavMeshQuery navQuery, long startRef, RcVec3f spos, RcVec3f epos, IDtQueryFilter filter, bool constrainByCircle, int count, ref List<RcVec3f> points)
|
public DtStatus FindRandomPointAroundCircle(DtNavMeshQuery navQuery, long startRef, long endRef, RcVec3f spos, RcVec3f epos, IDtQueryFilter filter, bool constrainByCircle, int count,
|
||||||
|
ref List<RcVec3f> points)
|
||||||
{
|
{
|
||||||
|
if (startRef == 0 || endRef == 0)
|
||||||
|
{
|
||||||
|
return DtStatus.DT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
float dx = epos.x - spos.x;
|
float dx = epos.x - spos.x;
|
||||||
float dz = epos.z - spos.z;
|
float dz = epos.z - spos.z;
|
||||||
float dist = (float)Math.Sqrt(dx * dx + dz * dz);
|
float dist = (float)Math.Sqrt(dx * dx + dz * dz);
|
||||||
|
@ -338,6 +344,7 @@ namespace DotRecast.Recast.Toolset.Tools
|
||||||
var frand = new FRand();
|
var frand = new FRand();
|
||||||
int prevCnt = points.Count;
|
int prevCnt = points.Count;
|
||||||
|
|
||||||
|
points = new List<RcVec3f>();
|
||||||
while (0 < count && points.Count < prevCnt + count)
|
while (0 < count && points.Count < prevCnt + count)
|
||||||
{
|
{
|
||||||
var status = navQuery.FindRandomPointAroundCircle(startRef, spos, dist, filter, frand, constraint,
|
var status = navQuery.FindRandomPointAroundCircle(startRef, spos, dist, filter, frand, constraint,
|
||||||
|
|
Loading…
Reference in New Issue