forked from bit/DotRecastNetSim
C# style GetPolyHeight
This commit is contained in:
parent
42583ab5d3
commit
d8d3a572c9
|
@ -430,13 +430,13 @@ namespace DotRecast.Detour.Crowd
|
||||||
if (status.Succeeded())
|
if (status.Succeeded())
|
||||||
{
|
{
|
||||||
m_path = MergeCorridorStartMoved(m_path, visited);
|
m_path = MergeCorridorStartMoved(m_path, visited);
|
||||||
|
|
||||||
// Adjust the position to stay on top of the navmesh.
|
// Adjust the position to stay on top of the navmesh.
|
||||||
m_pos = result;
|
m_pos = result;
|
||||||
Result<float> hr = navquery.GetPolyHeight(m_path[0], result);
|
status = navquery.GetPolyHeight(m_path[0], result, out var h);
|
||||||
if (hr.Succeeded())
|
if (status.Succeeded())
|
||||||
{
|
{
|
||||||
m_pos.y = hr.result;
|
m_pos.y = h;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -50,13 +50,12 @@ namespace DotRecast.Detour.Extras.Jumplink
|
||||||
RcAtomicFloat minHeight = new RcAtomicFloat(pt.y);
|
RcAtomicFloat minHeight = new RcAtomicFloat(pt.y);
|
||||||
navMeshQuery.QueryPolygons(pt, halfExtents, filter, new PolyQueryInvoker((tile, poly, refs) =>
|
navMeshQuery.QueryPolygons(pt, halfExtents, filter, new PolyQueryInvoker((tile, poly, refs) =>
|
||||||
{
|
{
|
||||||
Result<float> h = navMeshQuery.GetPolyHeight(refs, pt);
|
var status = navMeshQuery.GetPolyHeight(refs, pt, out var h);
|
||||||
if (h.Succeeded())
|
if (status.Succeeded())
|
||||||
{
|
{
|
||||||
float y = h.result;
|
if (h > minHeight.Get() && h < maxHeight)
|
||||||
if (y > minHeight.Get() && y < maxHeight)
|
|
||||||
{
|
{
|
||||||
minHeight.Exchange(y);
|
minHeight.Exchange(h);
|
||||||
found.Set(true);
|
found.Set(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -529,17 +529,19 @@ namespace DotRecast.Detour
|
||||||
/// @param[in] pos A position within the xz-bounds of the polygon. [(x, y, z)]
|
/// @param[in] pos A position within the xz-bounds of the polygon. [(x, y, z)]
|
||||||
/// @param[out] height The height at the surface of the polygon.
|
/// @param[out] height The height at the surface of the polygon.
|
||||||
/// @returns The status flags for the query.
|
/// @returns The status flags for the query.
|
||||||
public Result<float> GetPolyHeight(long refs, RcVec3f pos)
|
public DtStatus GetPolyHeight(long refs, RcVec3f pos, out float height)
|
||||||
{
|
{
|
||||||
|
height = default;
|
||||||
|
|
||||||
var status = m_nav.GetTileAndPolyByRef(refs, out var tile, out var poly);
|
var status = m_nav.GetTileAndPolyByRef(refs, out var tile, out var poly);
|
||||||
if (status.Failed())
|
if (status.Failed())
|
||||||
{
|
{
|
||||||
return Results.Of<float>(status, "");
|
return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!RcVec3f.IsFinite2D(pos))
|
if (!RcVec3f.IsFinite2D(pos))
|
||||||
{
|
{
|
||||||
return Results.InvalidParam<float>();
|
return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We used to return success for offmesh connections, but the
|
// We used to return success for offmesh connections, but the
|
||||||
|
@ -551,12 +553,18 @@ namespace DotRecast.Detour
|
||||||
var v0 = new RcVec3f { x = tile.data.verts[i], y = tile.data.verts[i + 1], z = tile.data.verts[i + 2] };
|
var v0 = new RcVec3f { x = tile.data.verts[i], y = tile.data.verts[i + 1], z = tile.data.verts[i + 2] };
|
||||||
i = poly.verts[1] * 3;
|
i = poly.verts[1] * 3;
|
||||||
var v1 = new RcVec3f { x = tile.data.verts[i], y = tile.data.verts[i + 1], z = tile.data.verts[i + 2] };
|
var v1 = new RcVec3f { x = tile.data.verts[i], y = tile.data.verts[i + 1], z = tile.data.verts[i + 2] };
|
||||||
var distSqr = DetourCommon.DistancePtSegSqr2D(pos, v0, v1, out var tseg);
|
DetourCommon.DistancePtSegSqr2D(pos, v0, v1, out var t);
|
||||||
return Results.Success(v0.y + (v1.y - v0.y) * tseg);
|
height = v0.y + (v1.y - v0.y) * t;
|
||||||
|
|
||||||
|
return DtStatus.DT_SUCCSESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
float? height = m_nav.GetPolyHeight(tile, poly, pos);
|
float? h = m_nav.GetPolyHeight(tile, poly, pos);
|
||||||
return null != height ? Results.Success(height.Value) : Results.InvalidParam<float>();
|
if (!h.HasValue)
|
||||||
|
return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM;
|
||||||
|
|
||||||
|
height = h.Value;
|
||||||
|
return DtStatus.DT_SUCCSESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Finds the polygon nearest to the specified center point.
|
/// Finds the polygon nearest to the specified center point.
|
||||||
|
|
|
@ -247,10 +247,10 @@ public class TestNavmeshTool : IRcTool
|
||||||
polys = PathUtils.FixupCorridor(polys, visited);
|
polys = PathUtils.FixupCorridor(polys, visited);
|
||||||
polys = PathUtils.FixupShortcuts(polys, m_navQuery);
|
polys = PathUtils.FixupShortcuts(polys, m_navQuery);
|
||||||
|
|
||||||
Result<float> polyHeight = m_navQuery.GetPolyHeight(polys[0], result);
|
var status = m_navQuery.GetPolyHeight(polys[0], result, out var h);
|
||||||
if (polyHeight.Succeeded())
|
if (status.Succeeded())
|
||||||
{
|
{
|
||||||
iterPos.y = polyHeight.result;
|
iterPos.y = h;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle end of path and off-mesh links when close enough.
|
// Handle end of path and off-mesh links when close enough.
|
||||||
|
@ -265,8 +265,7 @@ public class TestNavmeshTool : IRcTool
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (offMeshConnection
|
else if (offMeshConnection && PathUtils.InRange(iterPos, steerTarget.steerPos, SLOP, 1.0f))
|
||||||
&& PathUtils.InRange(iterPos, steerTarget.steerPos, SLOP, 1.0f))
|
|
||||||
{
|
{
|
||||||
// Reached off-mesh connection.
|
// Reached off-mesh connection.
|
||||||
// Advance the path up to and over the off-mesh connection.
|
// Advance the path up to and over the off-mesh connection.
|
||||||
|
@ -300,7 +299,8 @@ public class TestNavmeshTool : IRcTool
|
||||||
|
|
||||||
// Move position at the other side of the off-mesh link.
|
// Move position at the other side of the off-mesh link.
|
||||||
iterPos = endPos;
|
iterPos = endPos;
|
||||||
iterPos.y = m_navQuery.GetPolyHeight(polys[0], iterPos).result;
|
m_navQuery.GetPolyHeight(polys[0], iterPos, out var eh);
|
||||||
|
iterPos.y = eh;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -383,11 +383,10 @@ public class TestNavmeshTool : IRcTool
|
||||||
// Adjust height.
|
// Adjust height.
|
||||||
if (hit.result.path.Count > 0)
|
if (hit.result.path.Count > 0)
|
||||||
{
|
{
|
||||||
Result<float> result = m_navQuery
|
var result = m_navQuery.GetPolyHeight(hit.result.path[hit.result.path.Count - 1], m_hitPos, out var h);
|
||||||
.GetPolyHeight(hit.result.path[hit.result.path.Count - 1], m_hitPos);
|
|
||||||
if (result.Succeeded())
|
if (result.Succeeded())
|
||||||
{
|
{
|
||||||
m_hitPos.y = result.result;
|
m_hitPos.y = h;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue