remove class SteerTarget

This commit is contained in:
ikpil 2023-07-25 23:59:51 +09:00
parent 7f10d5814d
commit 336ba6b132
3 changed files with 26 additions and 54 deletions

View File

@ -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<long> path)
public static bool GetSteerTarget(DtNavMeshQuery navQuery, RcVec3f startPos, RcVec3f endPos,
float minTargetDist,
List<long> path,
out RcVec3f steerPos, out int steerPosFlag, out long steerPosRef)
{
steerPos = RcVec3f.Zero;
steerPosFlag = 0;
steerPosRef = 0;
// Find steer target.
var straightPath = new List<StraightPathItem>();
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)

View File

@ -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;
}
}
}

View File

@ -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];