From 336ba6b13260ddb693498b12b00402a1e8ce8e37 Mon Sep 17 00:00:00 2001 From: ikpil Date: Tue, 25 Jul 2023 23:59:51 +0900 Subject: [PATCH] remove class SteerTarget --- src/DotRecast.Detour/PathUtils.cs | 41 ++++++++----------- src/DotRecast.Detour/SteerTarget.cs | 20 --------- .../Tools/TestNavmeshToolImpl.cs | 19 ++++----- 3 files changed, 26 insertions(+), 54 deletions(-) delete mode 100644 src/DotRecast.Detour/SteerTarget.cs diff --git a/src/DotRecast.Detour/PathUtils.cs b/src/DotRecast.Detour/PathUtils.cs index d6479ce..034534d 100644 --- a/src/DotRecast.Detour/PathUtils.cs +++ b/src/DotRecast.Detour/PathUtils.cs @@ -28,24 +28,21 @@ namespace DotRecast.Detour { private const int MAX_STEER_POINTS = 3; - - public static SteerTarget GetSteerTarget(DtNavMeshQuery navQuery, RcVec3f startPos, RcVec3f endPos, - float minTargetDist, List path) + public static bool GetSteerTarget(DtNavMeshQuery navQuery, RcVec3f startPos, RcVec3f endPos, + float minTargetDist, + List path, + out RcVec3f steerPos, out int steerPosFlag, out long steerPosRef) { + steerPos = RcVec3f.Zero; + steerPosFlag = 0; + steerPosRef = 0; + // Find steer target. var straightPath = new List(); var result = navQuery.FindStraightPath(startPos, endPos, path, ref straightPath, MAX_STEER_POINTS, 0); if (result.Failed()) { - return null; - } - - float[] steerPoints = new float[straightPath.Count * 3]; - for (int i = 0; i < straightPath.Count; i++) - { - steerPoints[i * 3] = straightPath[i].GetPos().x; - steerPoints[i * 3 + 1] = straightPath[i].GetPos().y; - steerPoints[i * 3 + 2] = straightPath[i].GetPos().z; + return false; } // Find vertex far enough to steer to. @@ -53,26 +50,22 @@ namespace DotRecast.Detour while (ns < straightPath.Count) { // Stop at Off-Mesh link or when point is further than slop away. - if (((straightPath[ns].GetFlags() & DtNavMeshQuery.DT_STRAIGHTPATH_OFFMESH_CONNECTION) != 0) - || !InRange(straightPath[ns].GetPos(), startPos, minTargetDist, 1000.0f)) + if (((straightPath[ns].flags & DtNavMeshQuery.DT_STRAIGHTPATH_OFFMESH_CONNECTION) != 0) + || !InRange(straightPath[ns].pos, startPos, minTargetDist, 1000.0f)) break; ns++; } // Failed to find good point to steer to. if (ns >= straightPath.Count) - return null; + return false; - RcVec3f steerPos = RcVec3f.Of( - straightPath[ns].GetPos().x, - startPos.y, - straightPath[ns].GetPos().z - ); - int steerPosFlag = straightPath[ns].GetFlags(); - long steerPosRef = straightPath[ns].GetRef(); + steerPos = straightPath[ns].pos; + steerPos.y = startPos.y; + steerPosFlag = straightPath[ns].flags; + steerPosRef = straightPath[ns].refs; - SteerTarget target = new SteerTarget(steerPos, steerPosFlag, steerPosRef, steerPoints); - return target; + return true; } public static bool InRange(RcVec3f v1, RcVec3f v2, float r, float h) diff --git a/src/DotRecast.Detour/SteerTarget.cs b/src/DotRecast.Detour/SteerTarget.cs deleted file mode 100644 index 39edf60..0000000 --- a/src/DotRecast.Detour/SteerTarget.cs +++ /dev/null @@ -1,20 +0,0 @@ -using DotRecast.Core; - -namespace DotRecast.Detour -{ - public class SteerTarget - { - public readonly RcVec3f steerPos; - public readonly int steerPosFlag; - public readonly long steerPosRef; - public readonly float[] steerPoints; - - public SteerTarget(RcVec3f steerPos, int steerPosFlag, long steerPosRef, float[] steerPoints) - { - this.steerPos = steerPos; - this.steerPosFlag = steerPosFlag; - this.steerPosRef = steerPosRef; - this.steerPoints = steerPoints; - } - } -} \ No newline at end of file diff --git a/src/DotRecast.Recast.DemoTool/Tools/TestNavmeshToolImpl.cs b/src/DotRecast.Recast.DemoTool/Tools/TestNavmeshToolImpl.cs index 4c012a6..2b78f80 100644 --- a/src/DotRecast.Recast.DemoTool/Tools/TestNavmeshToolImpl.cs +++ b/src/DotRecast.Recast.DemoTool/Tools/TestNavmeshToolImpl.cs @@ -67,22 +67,21 @@ namespace DotRecast.Recast.DemoTool.Tools while (0 < polys.Count && smoothPath.Count < MAX_SMOOTH) { // Find location to steer towards. - SteerTarget steerTarget = PathUtils.GetSteerTarget(navQuery, iterPos, targetPos, SLOP, polys); - if (null == steerTarget) + if (!PathUtils.GetSteerTarget(navQuery, iterPos, targetPos, SLOP, + polys, out var steerPos, out var steerPosFlag, out var steerPosRef)) { break; } - bool endOfPath = (steerTarget.steerPosFlag & DtNavMeshQuery.DT_STRAIGHTPATH_END) != 0 + bool endOfPath = (steerPosFlag & DtNavMeshQuery.DT_STRAIGHTPATH_END) != 0 ? true : false; - bool offMeshConnection = (steerTarget.steerPosFlag - & DtNavMeshQuery.DT_STRAIGHTPATH_OFFMESH_CONNECTION) != 0 + bool offMeshConnection = (steerPosFlag & DtNavMeshQuery.DT_STRAIGHTPATH_OFFMESH_CONNECTION) != 0 ? true : false; // Find movement delta. - RcVec3f delta = steerTarget.steerPos.Subtract(iterPos); + RcVec3f delta = steerPos.Subtract(iterPos); float len = (float)Math.Sqrt(RcVec3f.Dot(delta, delta)); // If the steer target is end of path or off-mesh link, do not move past the location. if ((endOfPath || offMeshConnection) && len < STEP_SIZE) @@ -111,7 +110,7 @@ namespace DotRecast.Recast.DemoTool.Tools } // Handle end of path and off-mesh links when close enough. - if (endOfPath && PathUtils.InRange(iterPos, steerTarget.steerPos, SLOP, 1.0f)) + if (endOfPath && PathUtils.InRange(iterPos, steerPos, SLOP, 1.0f)) { // Reached end of path. iterPos = targetPos; @@ -122,7 +121,7 @@ namespace DotRecast.Recast.DemoTool.Tools break; } - else if (offMeshConnection && PathUtils.InRange(iterPos, steerTarget.steerPos, SLOP, 1.0f)) + else if (offMeshConnection && PathUtils.InRange(iterPos, steerPos, SLOP, 1.0f)) { // Reached off-mesh connection. RcVec3f startPos = RcVec3f.Zero; @@ -132,7 +131,7 @@ namespace DotRecast.Recast.DemoTool.Tools long prevRef = 0; long polyRef = polys[0]; int npos = 0; - while (npos < polys.Count && polyRef != steerTarget.steerPosRef) + while (npos < polys.Count && polyRef != steerPosRef) { prevRef = polyRef; polyRef = polys[npos]; @@ -311,7 +310,7 @@ namespace DotRecast.Recast.DemoTool.Tools { var status = navQuery.FindRandomPointAroundCircle(startRef, spos, dist, filter, frand, constraint, out var randomRef, out var randomPt); - + if (status.Succeeded()) { points.Add(randomPt);