forked from mirror/DotRecast
C# style GetPolyHeight
This commit is contained in:
parent
42583ab5d3
commit
d8d3a572c9
|
@ -430,13 +430,13 @@ namespace DotRecast.Detour.Crowd
|
|||
if (status.Succeeded())
|
||||
{
|
||||
m_path = MergeCorridorStartMoved(m_path, visited);
|
||||
|
||||
|
||||
// Adjust the position to stay on top of the navmesh.
|
||||
m_pos = result;
|
||||
Result<float> hr = navquery.GetPolyHeight(m_path[0], result);
|
||||
if (hr.Succeeded())
|
||||
status = navquery.GetPolyHeight(m_path[0], result, out var h);
|
||||
if (status.Succeeded())
|
||||
{
|
||||
m_pos.y = hr.result;
|
||||
m_pos.y = h;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -50,13 +50,12 @@ namespace DotRecast.Detour.Extras.Jumplink
|
|||
RcAtomicFloat minHeight = new RcAtomicFloat(pt.y);
|
||||
navMeshQuery.QueryPolygons(pt, halfExtents, filter, new PolyQueryInvoker((tile, poly, refs) =>
|
||||
{
|
||||
Result<float> h = navMeshQuery.GetPolyHeight(refs, pt);
|
||||
if (h.Succeeded())
|
||||
var status = navMeshQuery.GetPolyHeight(refs, pt, out var h);
|
||||
if (status.Succeeded())
|
||||
{
|
||||
float y = h.result;
|
||||
if (y > minHeight.Get() && y < maxHeight)
|
||||
if (h > minHeight.Get() && h < maxHeight)
|
||||
{
|
||||
minHeight.Exchange(y);
|
||||
minHeight.Exchange(h);
|
||||
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[out] height The height at the surface of the polygon.
|
||||
/// @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);
|
||||
if (status.Failed())
|
||||
{
|
||||
return Results.Of<float>(status, "");
|
||||
return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM;
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -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] };
|
||||
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 distSqr = DetourCommon.DistancePtSegSqr2D(pos, v0, v1, out var tseg);
|
||||
return Results.Success(v0.y + (v1.y - v0.y) * tseg);
|
||||
DetourCommon.DistancePtSegSqr2D(pos, v0, v1, out var t);
|
||||
height = v0.y + (v1.y - v0.y) * t;
|
||||
|
||||
return DtStatus.DT_SUCCSESS;
|
||||
}
|
||||
|
||||
float? height = m_nav.GetPolyHeight(tile, poly, pos);
|
||||
return null != height ? Results.Success(height.Value) : Results.InvalidParam<float>();
|
||||
float? h = m_nav.GetPolyHeight(tile, poly, pos);
|
||||
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.
|
||||
|
|
|
@ -247,10 +247,10 @@ public class TestNavmeshTool : IRcTool
|
|||
polys = PathUtils.FixupCorridor(polys, visited);
|
||||
polys = PathUtils.FixupShortcuts(polys, m_navQuery);
|
||||
|
||||
Result<float> polyHeight = m_navQuery.GetPolyHeight(polys[0], result);
|
||||
if (polyHeight.Succeeded())
|
||||
var status = m_navQuery.GetPolyHeight(polys[0], result, out var h);
|
||||
if (status.Succeeded())
|
||||
{
|
||||
iterPos.y = polyHeight.result;
|
||||
iterPos.y = h;
|
||||
}
|
||||
|
||||
// Handle end of path and off-mesh links when close enough.
|
||||
|
@ -265,8 +265,7 @@ public class TestNavmeshTool : IRcTool
|
|||
|
||||
break;
|
||||
}
|
||||
else if (offMeshConnection
|
||||
&& PathUtils.InRange(iterPos, steerTarget.steerPos, SLOP, 1.0f))
|
||||
else if (offMeshConnection && PathUtils.InRange(iterPos, steerTarget.steerPos, SLOP, 1.0f))
|
||||
{
|
||||
// Reached 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.
|
||||
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.
|
||||
if (hit.result.path.Count > 0)
|
||||
{
|
||||
Result<float> result = m_navQuery
|
||||
.GetPolyHeight(hit.result.path[hit.result.path.Count - 1], m_hitPos);
|
||||
var result = m_navQuery.GetPolyHeight(hit.result.path[hit.result.path.Count - 1], m_hitPos, out var h);
|
||||
if (result.Succeeded())
|
||||
{
|
||||
m_hitPos.y = result.result;
|
||||
m_hitPos.y = h;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue