forked from mirror/DotRecast
remove FindRandomPointResult 3st
This commit is contained in:
parent
e775e7ad83
commit
83da4196e4
|
@ -202,11 +202,7 @@ namespace DotRecast.Detour
|
||||||
public DtStatus FindRandomPointAroundCircle(long startRef, RcVec3f centerPos, float maxRadius,
|
public DtStatus FindRandomPointAroundCircle(long startRef, RcVec3f centerPos, float maxRadius,
|
||||||
IDtQueryFilter filter, FRand frand, out long randomRef, out RcVec3f randomPt)
|
IDtQueryFilter filter, FRand frand, out long randomRef, out RcVec3f randomPt)
|
||||||
{
|
{
|
||||||
var result = FindRandomPointAroundCircle(startRef, centerPos, maxRadius, filter, frand, NoOpPolygonByCircleConstraint.Noop);
|
return FindRandomPointAroundCircle(startRef, centerPos, maxRadius, filter, frand, NoOpPolygonByCircleConstraint.Noop, out randomRef, out randomPt);
|
||||||
randomRef = result.result.GetRandomRef();
|
|
||||||
randomPt = result.result.GetRandomPt();
|
|
||||||
|
|
||||||
return result.status;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -227,28 +223,27 @@ namespace DotRecast.Detour
|
||||||
public DtStatus FindRandomPointWithinCircle(long startRef, RcVec3f centerPos, float maxRadius,
|
public DtStatus FindRandomPointWithinCircle(long startRef, RcVec3f centerPos, float maxRadius,
|
||||||
IDtQueryFilter filter, FRand frand, out long randomRef, out RcVec3f randomPt)
|
IDtQueryFilter filter, FRand frand, out long randomRef, out RcVec3f randomPt)
|
||||||
{
|
{
|
||||||
var result = FindRandomPointAroundCircle(startRef, centerPos, maxRadius, filter, frand, StrictPolygonByCircleConstraint.Strict);
|
return FindRandomPointAroundCircle(startRef, centerPos, maxRadius, filter, frand, StrictPolygonByCircleConstraint.Strict, out randomRef, out randomPt);
|
||||||
randomRef = result.result.GetRandomRef();
|
|
||||||
randomPt = result.result.GetRandomPt();
|
|
||||||
|
|
||||||
return result.status;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Result<FindRandomPointResult> FindRandomPointAroundCircle(long startRef, RcVec3f centerPos, float maxRadius,
|
public DtStatus FindRandomPointAroundCircle(long startRef, RcVec3f centerPos, float maxRadius,
|
||||||
IDtQueryFilter filter, FRand frand,
|
IDtQueryFilter filter, FRand frand, IPolygonByCircleConstraint constraint,
|
||||||
IPolygonByCircleConstraint constraint)
|
out long randomRef, out RcVec3f randomPt)
|
||||||
{
|
{
|
||||||
|
randomRef = startRef;
|
||||||
|
randomPt = centerPos;
|
||||||
|
|
||||||
// Validate input
|
// Validate input
|
||||||
if (!m_nav.IsValidPolyRef(startRef) || !RcVec3f.IsFinite(centerPos) || maxRadius < 0
|
if (!m_nav.IsValidPolyRef(startRef) || !RcVec3f.IsFinite(centerPos) || maxRadius < 0
|
||||||
|| !float.IsFinite(maxRadius) || null == filter || null == frand)
|
|| !float.IsFinite(maxRadius) || null == filter || null == frand)
|
||||||
{
|
{
|
||||||
return Results.InvalidParam<FindRandomPointResult>();
|
return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_nav.GetTileAndPolyByRefUnsafe(startRef, out var startTile, out var startPoly);
|
m_nav.GetTileAndPolyByRefUnsafe(startRef, out var startTile, out var startPoly);
|
||||||
if (!filter.PassFilter(startRef, startTile, startPoly))
|
if (!filter.PassFilter(startRef, startTile, startPoly))
|
||||||
{
|
{
|
||||||
return Results.InvalidParam<FindRandomPointResult>("Invalid start ref");
|
return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_nodePool.Clear();
|
m_nodePool.Clear();
|
||||||
|
@ -263,6 +258,8 @@ namespace DotRecast.Detour
|
||||||
startNode.flags = DT_NODE_OPEN;
|
startNode.flags = DT_NODE_OPEN;
|
||||||
m_openList.Push(startNode);
|
m_openList.Push(startNode);
|
||||||
|
|
||||||
|
DtStatus status = DtStatus.DT_SUCCSESS;
|
||||||
|
|
||||||
float radiusSqr = maxRadius * maxRadius;
|
float radiusSqr = maxRadius * maxRadius;
|
||||||
float areaSum = 0.0f;
|
float areaSum = 0.0f;
|
||||||
|
|
||||||
|
@ -360,6 +357,11 @@ namespace DotRecast.Detour
|
||||||
}
|
}
|
||||||
|
|
||||||
DtNode neighbourNode = m_nodePool.GetNode(neighbourRef);
|
DtNode neighbourNode = m_nodePool.GetNode(neighbourRef);
|
||||||
|
if (null == neighbourNode)
|
||||||
|
{
|
||||||
|
status |= DtStatus.DT_OUT_OF_NODES;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if ((neighbourNode.flags & DtNode.DT_NODE_CLOSED) != 0)
|
if ((neighbourNode.flags & DtNode.DT_NODE_CLOSED) != 0)
|
||||||
{
|
{
|
||||||
|
@ -399,7 +401,7 @@ namespace DotRecast.Detour
|
||||||
|
|
||||||
if (randomPoly == null)
|
if (randomPoly == null)
|
||||||
{
|
{
|
||||||
return Results.Failure<FindRandomPointResult>();
|
return DtStatus.DT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Randomly pick point on polygon.
|
// Randomly pick point on polygon.
|
||||||
|
@ -409,7 +411,9 @@ namespace DotRecast.Detour
|
||||||
float[] areas = new float[randomPolyVerts.Length / 3];
|
float[] areas = new float[randomPolyVerts.Length / 3];
|
||||||
RcVec3f pt = DetourCommon.RandomPointInConvexPoly(randomPolyVerts, randomPolyVerts.Length / 3, areas, s, t);
|
RcVec3f pt = DetourCommon.RandomPointInConvexPoly(randomPolyVerts, randomPolyVerts.Length / 3, areas, s, t);
|
||||||
ClosestPointOnPoly(randomPolyRef, pt, out var closest, out var _);
|
ClosestPointOnPoly(randomPolyRef, pt, out var closest, out var _);
|
||||||
return Results.Success(new FindRandomPointResult(randomPolyRef, closest));
|
Results.Success(new FindRandomPointResult(randomPolyRef, closest));
|
||||||
|
|
||||||
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -64,7 +64,6 @@ namespace DotRecast.Detour
|
||||||
public DtNode GetNode(long id, int state)
|
public DtNode GetNode(long id, int state)
|
||||||
{
|
{
|
||||||
var hasNode = m_map.TryGetValue(id, out var nodes);
|
var hasNode = m_map.TryGetValue(id, out var nodes);
|
||||||
;
|
|
||||||
if (nodes != null)
|
if (nodes != null)
|
||||||
{
|
{
|
||||||
foreach (DtNode node in nodes)
|
foreach (DtNode node in nodes)
|
||||||
|
|
|
@ -491,14 +491,14 @@ public class TestNavmeshTool : ITool
|
||||||
IPolygonByCircleConstraint constraint = constrainByCircle
|
IPolygonByCircleConstraint constraint = constrainByCircle
|
||||||
? StrictPolygonByCircleConstraint.Strict
|
? StrictPolygonByCircleConstraint.Strict
|
||||||
: NoOpPolygonByCircleConstraint.Noop;
|
: NoOpPolygonByCircleConstraint.Noop;
|
||||||
|
|
||||||
for (int i = 0; i < 200; i++)
|
for (int i = 0; i < 200; i++)
|
||||||
{
|
{
|
||||||
Result<FindRandomPointResult> result = m_navQuery.FindRandomPointAroundCircle(m_startRef, m_spos, dist,
|
var status = m_navQuery.FindRandomPointAroundCircle(m_startRef, m_spos, dist, m_filter, new FRand(), constraint,
|
||||||
m_filter, new FRand(), constraint);
|
out var randomRef, out var randomPt);
|
||||||
if (result.Succeeded())
|
if (status.Succeeded())
|
||||||
{
|
{
|
||||||
randomPoints.Add(result.result.GetRandomPt());
|
randomPoints.Add(randomPt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue