forked from bit/DotRecastNetSim
remove MoveAlongSurfaceResult
This commit is contained in:
parent
96928355c1
commit
42583ab5d3
|
@ -426,13 +426,14 @@ namespace DotRecast.Detour.Crowd
|
|||
public bool MovePosition(RcVec3f npos, DtNavMeshQuery navquery, IDtQueryFilter filter)
|
||||
{
|
||||
// Move along navmesh and update new position.
|
||||
Result<MoveAlongSurfaceResult> masResult = navquery.MoveAlongSurface(m_path[0], m_pos, npos, filter);
|
||||
if (masResult.Succeeded())
|
||||
var status = navquery.MoveAlongSurface(m_path[0], m_pos, npos, filter, out var result, out var visited);
|
||||
if (status.Succeeded())
|
||||
{
|
||||
m_path = MergeCorridorStartMoved(m_path, masResult.result.GetVisited());
|
||||
m_path = MergeCorridorStartMoved(m_path, visited);
|
||||
|
||||
// Adjust the position to stay on top of the navmesh.
|
||||
m_pos = masResult.result.GetResultPos();
|
||||
Result<float> hr = navquery.GetPolyHeight(m_path[0], masResult.result.GetResultPos());
|
||||
m_pos = result;
|
||||
Result<float> hr = navquery.GetPolyHeight(m_path[0], result);
|
||||
if (hr.Succeeded())
|
||||
{
|
||||
m_pos.y = hr.result;
|
||||
|
@ -464,17 +465,17 @@ namespace DotRecast.Detour.Crowd
|
|||
public bool MoveTargetPosition(RcVec3f npos, DtNavMeshQuery navquery, IDtQueryFilter filter)
|
||||
{
|
||||
// Move along navmesh and update new position.
|
||||
Result<MoveAlongSurfaceResult> masResult = navquery.MoveAlongSurface(m_path[m_path.Count - 1], m_target, npos, filter);
|
||||
if (masResult.Succeeded())
|
||||
var status = navquery.MoveAlongSurface(m_path[m_path.Count - 1], m_target, npos, filter, out var result, out var visited);
|
||||
if (status.Succeeded())
|
||||
{
|
||||
m_path = MergeCorridorEndMoved(m_path, masResult.result.GetVisited());
|
||||
m_path = MergeCorridorEndMoved(m_path, visited);
|
||||
// TODO: should we do that?
|
||||
// Adjust the position to stay on top of the navmesh.
|
||||
/*
|
||||
* float h = m_target.y; navquery->GetPolyHeight(m_path[m_npath-1],
|
||||
* result, &h); result.y = h;
|
||||
*/
|
||||
m_target = masResult.result.GetResultPos();
|
||||
m_target = result;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -1785,18 +1785,27 @@ namespace DotRecast.Detour
|
|||
/// position.
|
||||
///
|
||||
/// Moves from the start to the end position constrained to the navigation mesh.
|
||||
/// @param[in] startRef The reference id of the start polygon.
|
||||
/// @param[in] startPos A position of the mover within the start polygon. [(x, y, x)]
|
||||
/// @param[in] endPos The desired end position of the mover. [(x, y, z)]
|
||||
/// @param[in] filter The polygon filter to apply to the query.
|
||||
/// @returns Path
|
||||
public Result<MoveAlongSurfaceResult> MoveAlongSurface(long startRef, RcVec3f startPos, RcVec3f endPos, IDtQueryFilter filter)
|
||||
/// @param[in] startRef The reference id of the start polygon.
|
||||
/// @param[in] startPos A position of the mover within the start polygon. [(x, y, x)]
|
||||
/// @param[in] endPos The desired end position of the mover. [(x, y, z)]
|
||||
/// @param[in] filter The polygon filter to apply to the query.
|
||||
/// @param[out] resultPos The result position of the mover. [(x, y, z)]
|
||||
/// @param[out] visited The reference ids of the polygons visited during the move.
|
||||
/// @param[out] visitedCount The number of polygons visited during the move.
|
||||
/// @param[in] maxVisitedSize The maximum number of polygons the @p visited array can hold.
|
||||
/// @returns The status flags for the query.
|
||||
public DtStatus MoveAlongSurface(long startRef, RcVec3f startPos, RcVec3f endPos,
|
||||
IDtQueryFilter filter,
|
||||
out RcVec3f resultPos, out List<long> visited)
|
||||
{
|
||||
resultPos = RcVec3f.Zero;
|
||||
visited = new List<long>();
|
||||
|
||||
// Validate input
|
||||
if (!m_nav.IsValidPolyRef(startRef) || !RcVec3f.IsFinite(startPos)
|
||||
|| !RcVec3f.IsFinite(endPos) || null == filter)
|
||||
{
|
||||
return Results.InvalidParam<MoveAlongSurfaceResult>();
|
||||
return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM;
|
||||
}
|
||||
|
||||
DtNodePool tinyNodePool = new DtNodePool();
|
||||
|
@ -1932,7 +1941,6 @@ namespace DotRecast.Detour
|
|||
}
|
||||
}
|
||||
|
||||
List<long> visited = new List<long>();
|
||||
if (bestNode != null)
|
||||
{
|
||||
// Reverse the path.
|
||||
|
@ -1955,7 +1963,9 @@ namespace DotRecast.Detour
|
|||
} while (node != null);
|
||||
}
|
||||
|
||||
return Results.Success(new MoveAlongSurfaceResult(bestPos, visited));
|
||||
resultPos = bestPos;
|
||||
|
||||
return DtStatus.DT_SUCCSESS;
|
||||
}
|
||||
|
||||
protected Result<PortalResult> GetPortalPoints(long from, long to)
|
||||
|
|
|
@ -24,8 +24,6 @@ namespace DotRecast.Detour
|
|||
{
|
||||
public readonly struct DtStatus
|
||||
{
|
||||
public static readonly DtStatus Empty = new DtStatus(0);
|
||||
|
||||
// High level status.
|
||||
public static readonly DtStatus DT_FAILURE = new DtStatus(1u << 31); // Operation failed.
|
||||
public static readonly DtStatus DT_SUCCSESS = new DtStatus(1u << 30); // Operation succeed.
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
/*
|
||||
Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
|
||||
recast4j copyright (c) 2015-2019 Piotr Piastucki piotr@jtilia.org
|
||||
DotRecast Copyright (c) 2023 Choi Ikpil ikpil@naver.com
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using DotRecast.Core;
|
||||
|
||||
namespace DotRecast.Detour.QueryResults
|
||||
{
|
||||
public class MoveAlongSurfaceResult
|
||||
{
|
||||
/** The result position of the mover. [(x, y, z)] */
|
||||
private readonly RcVec3f resultPos;
|
||||
|
||||
/** The reference ids of the polygons visited during the move. */
|
||||
private readonly List<long> visited;
|
||||
|
||||
public MoveAlongSurfaceResult(RcVec3f resultPos, List<long> visited)
|
||||
{
|
||||
this.resultPos = resultPos;
|
||||
this.visited = visited;
|
||||
}
|
||||
|
||||
public RcVec3f GetResultPos()
|
||||
{
|
||||
return resultPos;
|
||||
}
|
||||
|
||||
public List<long> GetVisited()
|
||||
{
|
||||
return visited;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -238,20 +238,16 @@ public class TestNavmeshTool : IRcTool
|
|||
}
|
||||
|
||||
RcVec3f moveTgt = RcVec3f.Mad(iterPos, delta, len);
|
||||
|
||||
// Move
|
||||
Result<MoveAlongSurfaceResult> result = m_navQuery.MoveAlongSurface(polys[0], iterPos,
|
||||
moveTgt, m_filter);
|
||||
MoveAlongSurfaceResult moveAlongSurface = result.result;
|
||||
m_navQuery.MoveAlongSurface(polys[0], iterPos, moveTgt, m_filter, out var result, out var visited);
|
||||
|
||||
iterPos.x = moveAlongSurface.GetResultPos().x;
|
||||
iterPos.y = moveAlongSurface.GetResultPos().y;
|
||||
iterPos.z = moveAlongSurface.GetResultPos().z;
|
||||
iterPos = result;
|
||||
|
||||
List<long> visited = result.result.GetVisited();
|
||||
polys = PathUtils.FixupCorridor(polys, visited);
|
||||
polys = PathUtils.FixupShortcuts(polys, m_navQuery);
|
||||
|
||||
Result<float> polyHeight = m_navQuery.GetPolyHeight(polys[0], moveAlongSurface.GetResultPos());
|
||||
Result<float> polyHeight = m_navQuery.GetPolyHeight(polys[0], result);
|
||||
if (polyHeight.Succeeded())
|
||||
{
|
||||
iterPos.y = polyHeight.result;
|
||||
|
|
|
@ -74,18 +74,18 @@ public class MoveAlongSurfaceTest : AbstractDetourTest
|
|||
long startRef = startRefs[i];
|
||||
RcVec3f startPos = startPoss[i];
|
||||
RcVec3f endPos = endPoss[i];
|
||||
Result<MoveAlongSurfaceResult> result = query.MoveAlongSurface(startRef, startPos, endPos, filter);
|
||||
Assert.That(result.Succeeded(), Is.True);
|
||||
MoveAlongSurfaceResult path = result.result;
|
||||
var status = query.MoveAlongSurface(startRef, startPos, endPos, filter, out var result, out var visited);
|
||||
Assert.That(status.Succeeded(), Is.True);
|
||||
|
||||
for (int v = 0; v < 3; v++)
|
||||
{
|
||||
Assert.That(path.GetResultPos()[v], Is.EqualTo(POSITION[i][v]).Within(0.01f));
|
||||
Assert.That(result[v], Is.EqualTo(POSITION[i][v]).Within(0.01f));
|
||||
}
|
||||
|
||||
Assert.That(path.GetVisited().Count, Is.EqualTo(VISITED[i].Length));
|
||||
Assert.That(visited.Count, Is.EqualTo(VISITED[i].Length));
|
||||
for (int j = 0; j < POSITION[i].Length; j++)
|
||||
{
|
||||
Assert.That(path.GetVisited()[j], Is.EqualTo(VISITED[i][j]));
|
||||
Assert.That(visited[j], Is.EqualTo(VISITED[i][j]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue