refactor: RAYCAST

This commit is contained in:
ikpil 2023-09-10 13:47:18 +09:00
parent 5fd07d1e07
commit 539a028f58
2 changed files with 17 additions and 23 deletions

View File

@ -63,6 +63,8 @@ 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;
// for mode RANDOM_POINTS_IN_CIRCLE
private List<RcVec3f> _randomPoints = new(); private List<RcVec3f> _randomPoints = new();
public TestNavmeshSampleTool() public TestNavmeshSampleTool()
@ -709,23 +711,9 @@ public class TestNavmeshSampleTool : ISampleTool
} }
else if (_mode == RcTestNavmeshToolMode.RAYCAST) else if (_mode == RcTestNavmeshToolMode.RAYCAST)
{ {
m_straightPath = null; m_straightPath?.Clear();
if (m_sposSet && m_eposSet && m_startRef != 0) _tool.Raycast(navQuery, m_startRef, m_endRef, m_spos, m_epos, m_filter,
{ ref m_polys, ref m_straightPath, ref m_hitPos, ref m_hitNormal, ref m_hitResult);
var polys = new List<long>();
var straightPath = new List<StraightPathItem>();
var status = _tool.Raycast(navQuery, m_startRef, m_spos, m_epos, m_filter,
ref polys, ref straightPath, out var hitPos, out var hitNormal, out var hitResult);
if (status.Succeeded())
{
m_polys = polys;
m_straightPath = straightPath;
m_hitPos = hitPos;
m_hitNormal = hitNormal;
m_hitResult = hitResult;
}
}
} }
else if (_mode == RcTestNavmeshToolMode.DISTANCE_TO_WALL) else if (_mode == RcTestNavmeshToolMode.DISTANCE_TO_WALL)
{ {

View File

@ -216,18 +216,23 @@ namespace DotRecast.Recast.Toolset.Tools
} }
public DtStatus Raycast(DtNavMeshQuery navQuery, long startRef, RcVec3f startPos, RcVec3f endPos, IDtQueryFilter filter, public DtStatus Raycast(DtNavMeshQuery navQuery, long startRef, long endRef, RcVec3f startPos, RcVec3f endPos, IDtQueryFilter filter,
ref List<long> polys, ref List<StraightPathItem> straightPath, out RcVec3f hitPos, out RcVec3f hitNormal, out bool hitResult) ref List<long> polys, ref List<StraightPathItem> straightPath, ref RcVec3f hitPos, ref RcVec3f hitNormal, ref bool hitResult)
{ {
hitPos = RcVec3f.Zero; if (startRef == 0 || endRef == 0)
hitNormal = RcVec3f.Zero; {
hitResult = false; return DtStatus.DT_FAILURE;
}
var status = navQuery.Raycast(startRef, startPos, endPos, filter, 0, 0, out var rayHit); var status = navQuery.Raycast(startRef, startPos, endPos, filter, 0, 0, out var rayHit);
if (!status.Succeeded()) if (!status.Succeeded())
{
return status; return status;
}
// results ...
polys = rayHit.path; polys = rayHit.path;
if (rayHit.t > 1) if (rayHit.t > 1)
{ {
// No hit // No hit
@ -252,6 +257,7 @@ namespace DotRecast.Recast.Toolset.Tools
} }
} }
straightPath ??= new List<StraightPathItem>();
straightPath.Clear(); straightPath.Clear();
straightPath.Add(new StraightPathItem(startPos, 0, 0)); straightPath.Add(new StraightPathItem(startPos, 0, 0));
straightPath.Add(new StraightPathItem(hitPos, 0, 0)); straightPath.Add(new StraightPathItem(hitPos, 0, 0));