From 539a028f58b6d905fedb87c61208c1eb7c783825 Mon Sep 17 00:00:00 2001 From: ikpil Date: Sun, 10 Sep 2023 13:47:18 +0900 Subject: [PATCH] refactor: RAYCAST --- .../Tools/TestNavmeshSampleTool.cs | 22 +++++-------------- .../Tools/RcTestNavMeshTool.cs | 18 ++++++++++----- 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/src/DotRecast.Recast.Demo/Tools/TestNavmeshSampleTool.cs b/src/DotRecast.Recast.Demo/Tools/TestNavmeshSampleTool.cs index 91d9498..b8a103b 100644 --- a/src/DotRecast.Recast.Demo/Tools/TestNavmeshSampleTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/TestNavmeshSampleTool.cs @@ -63,6 +63,8 @@ public class TestNavmeshSampleTool : ISampleTool private RcVec3f[] m_queryPoly = new RcVec3f[4]; private List m_smoothPath; private DtStatus m_pathFindStatus = DtStatus.DT_FAILURE; + + // for mode RANDOM_POINTS_IN_CIRCLE private List _randomPoints = new(); public TestNavmeshSampleTool() @@ -709,23 +711,9 @@ public class TestNavmeshSampleTool : ISampleTool } else if (_mode == RcTestNavmeshToolMode.RAYCAST) { - m_straightPath = null; - if (m_sposSet && m_eposSet && m_startRef != 0) - { - var polys = new List(); - var straightPath = new List(); - 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; - } - } + m_straightPath?.Clear(); + _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); } else if (_mode == RcTestNavmeshToolMode.DISTANCE_TO_WALL) { diff --git a/src/DotRecast.Recast.Toolset/Tools/RcTestNavMeshTool.cs b/src/DotRecast.Recast.Toolset/Tools/RcTestNavMeshTool.cs index 4c65be1..9cdd62d 100644 --- a/src/DotRecast.Recast.Toolset/Tools/RcTestNavMeshTool.cs +++ b/src/DotRecast.Recast.Toolset/Tools/RcTestNavMeshTool.cs @@ -216,18 +216,23 @@ namespace DotRecast.Recast.Toolset.Tools } - public DtStatus Raycast(DtNavMeshQuery navQuery, long startRef, RcVec3f startPos, RcVec3f endPos, IDtQueryFilter filter, - ref List polys, ref List straightPath, out RcVec3f hitPos, out RcVec3f hitNormal, out bool hitResult) + public DtStatus Raycast(DtNavMeshQuery navQuery, long startRef, long endRef, RcVec3f startPos, RcVec3f endPos, IDtQueryFilter filter, + ref List polys, ref List straightPath, ref RcVec3f hitPos, ref RcVec3f hitNormal, ref bool hitResult) { - hitPos = RcVec3f.Zero; - hitNormal = RcVec3f.Zero; - hitResult = false; + if (startRef == 0 || endRef == 0) + { + return DtStatus.DT_FAILURE; + } var status = navQuery.Raycast(startRef, startPos, endPos, filter, 0, 0, out var rayHit); if (!status.Succeeded()) + { return status; - + } + + // results ... polys = rayHit.path; + if (rayHit.t > 1) { // No hit @@ -252,6 +257,7 @@ namespace DotRecast.Recast.Toolset.Tools } } + straightPath ??= new List(); straightPath.Clear(); straightPath.Add(new StraightPathItem(startPos, 0, 0)); straightPath.Add(new StraightPathItem(hitPos, 0, 0));