change interface raycast

This commit is contained in:
ikpil 2023-06-16 19:15:34 +09:00
parent bf8d5f165d
commit c3846198d1
4 changed files with 49 additions and 44 deletions

View File

@ -318,12 +318,12 @@ namespace DotRecast.Detour.Crowd
var delta = next.Subtract(m_pos); var delta = next.Subtract(m_pos);
RcVec3f goal = RcVec3f.Mad(m_pos, delta, pathOptimizationRange / dist); RcVec3f goal = RcVec3f.Mad(m_pos, delta, pathOptimizationRange / dist);
Result<DtRaycastHit> rc = navquery.Raycast(m_path[0], m_pos, goal, filter, 0, 0); var status = navquery.Raycast(m_path[0], m_pos, goal, filter, 0, 0, out var rayHit);
if (rc.Succeeded()) if (status.Succeeded())
{ {
if (rc.result.path.Count > 1 && rc.result.t > 0.99f) if (rayHit.path.Count > 1 && rayHit.t > 0.99f)
{ {
m_path = MergeCorridorStartShortcut(m_path, rc.result.path); m_path = MergeCorridorStartShortcut(m_path, rayHit.path);
} }
} }
} }

View File

@ -927,17 +927,17 @@ namespace DotRecast.Detour
List<long> shortcut = null; List<long> shortcut = null;
if (tryLOS) if (tryLOS)
{ {
Result<DtRaycastHit> rayHit = Raycast(parentRef, parentNode.pos, neighbourPos, filter, status = Raycast(parentRef, parentNode.pos, neighbourPos, filter,
DT_RAYCAST_USE_COSTS, grandpaRef); DT_RAYCAST_USE_COSTS, grandpaRef, out var rayHit);
if (rayHit.Succeeded()) if (status.Succeeded())
{ {
foundShortCut = rayHit.result.t >= 1.0f; foundShortCut = rayHit.t >= 1.0f;
if (foundShortCut) if (foundShortCut)
{ {
shortcut = rayHit.result.path; shortcut = rayHit.path;
// shortcut found using raycast. Using shorter cost // shortcut found using raycast. Using shorter cost
// instead // instead
cost = parentNode.cost + rayHit.result.pathCost; cost = parentNode.cost + rayHit.pathCost;
} }
} }
} }
@ -1246,17 +1246,17 @@ namespace DotRecast.Detour
List<long> shortcut = null; List<long> shortcut = null;
if (tryLOS) if (tryLOS)
{ {
Result<DtRaycastHit> rayHit = Raycast(parentRef, parentNode.pos, neighbourPos, m_query.filter, status = Raycast(parentRef, parentNode.pos, neighbourPos, m_query.filter,
DT_RAYCAST_USE_COSTS, grandpaRef); DT_RAYCAST_USE_COSTS, grandpaRef, out var rayHit);
if (rayHit.Succeeded()) if (status.Succeeded())
{ {
foundShortCut = rayHit.result.t >= 1.0f; foundShortCut = rayHit.t >= 1.0f;
if (foundShortCut) if (foundShortCut)
{ {
shortcut = rayHit.result.path; shortcut = rayHit.path;
// shortcut found using raycast. Using shorter cost // shortcut found using raycast. Using shorter cost
// instead // instead
cost = parentNode.cost + rayHit.result.pathCost; cost = parentNode.cost + rayHit.pathCost;
} }
} }
} }
@ -2186,17 +2186,20 @@ namespace DotRecast.Detour
/// @param[out] pathCount The number of visited polygons. [opt] /// @param[out] pathCount The number of visited polygons. [opt]
/// @param[in] maxPath The maximum number of polygons the @p path array can hold. /// @param[in] maxPath The maximum number of polygons the @p path array can hold.
/// @returns The status flags for the query. /// @returns The status flags for the query.
public Result<DtRaycastHit> Raycast(long startRef, RcVec3f startPos, RcVec3f endPos, IDtQueryFilter filter, int options, public DtStatus Raycast(long startRef, RcVec3f startPos, RcVec3f endPos, IDtQueryFilter filter, int options,
long prevRef) long prevRef, out DtRaycastHit hit)
{ {
hit = null;
// Validate input // Validate input
if (!m_nav.IsValidPolyRef(startRef) || !RcVec3f.IsFinite(startPos) || !RcVec3f.IsFinite(endPos) || null == filter if (!m_nav.IsValidPolyRef(startRef) || !RcVec3f.IsFinite(startPos) || !RcVec3f.IsFinite(endPos)
|| null == filter
|| (prevRef != 0 && !m_nav.IsValidPolyRef(prevRef))) || (prevRef != 0 && !m_nav.IsValidPolyRef(prevRef)))
{ {
return Results.InvalidParam<DtRaycastHit>(); return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM;
} }
DtRaycastHit hit = new DtRaycastHit(); hit = new DtRaycastHit();
float[] verts = new float[m_nav.GetMaxVertsPerPoly() * 3 + 3]; float[] verts = new float[m_nav.GetMaxVertsPerPoly() * 3 + 3];
@ -2235,7 +2238,7 @@ namespace DotRecast.Detour
if (!iresult.intersects) if (!iresult.intersects)
{ {
// Could not hit the polygon, keep the old t and report hit. // Could not hit the polygon, keep the old t and report hit.
return Results.Success(hit); return DtStatus.DT_SUCCSESS;
} }
hit.hitEdgeIndex = iresult.segMax; hit.hitEdgeIndex = iresult.segMax;
@ -2261,7 +2264,7 @@ namespace DotRecast.Detour
curRef, tile, poly); curRef, tile, poly);
} }
return Results.Success(hit); return DtStatus.DT_SUCCSESS;
} }
// Follow neighbours. // Follow neighbours.
@ -2390,7 +2393,7 @@ namespace DotRecast.Detour
hit.hitNormal.y = 0; hit.hitNormal.y = 0;
hit.hitNormal.z = -dx; hit.hitNormal.z = -dx;
hit.hitNormal.Normalize(); hit.hitNormal.Normalize();
return Results.Success(hit); return DtStatus.DT_SUCCSESS;
} }
// No hit, advance to neighbour polygon. // No hit, advance to neighbour polygon.
@ -2402,7 +2405,7 @@ namespace DotRecast.Detour
poly = nextPoly; poly = nextPoly;
} }
return Results.Success(hit); return DtStatus.DT_SUCCSESS;
} }
/// @par /// @par

View File

@ -361,16 +361,16 @@ namespace DotRecast.Detour
bool foundShortCut = false; bool foundShortCut = false;
if (tryLOS) if (tryLOS)
{ {
Result<DtRaycastHit> rayHit = Raycast(parentRef, parentNode.pos, neighbourNode.pos, m_query.filter, status = Raycast(parentRef, parentNode.pos, neighbourNode.pos, m_query.filter,
DT_RAYCAST_USE_COSTS, grandpaRef); DT_RAYCAST_USE_COSTS, grandpaRef, out var rayHit);
if (rayHit.Succeeded()) if (status.Succeeded())
{ {
foundShortCut = rayHit.result.t >= 1.0f; foundShortCut = rayHit.t >= 1.0f;
if (foundShortCut) if (foundShortCut)
{ {
// shortcut found using raycast. Using shorter cost // shortcut found using raycast. Using shorter cost
// instead // instead
cost = parentNode.cost + rayHit.result.pathCost; cost = parentNode.cost + rayHit.pathCost;
} }
} }
} }
@ -505,10 +505,11 @@ namespace DotRecast.Detour
DtNode next = m_nodePool.GetNodeAtIdx(node.pidx); DtNode next = m_nodePool.GetNodeAtIdx(node.pidx);
if ((node.flags & DtNode.DT_NODE_PARENT_DETACHED) != 0) if ((node.flags & DtNode.DT_NODE_PARENT_DETACHED) != 0)
{ {
Result<DtRaycastHit> iresult = Raycast(node.id, node.pos, next.pos, m_query.filter, 0, 0); var status2 = Raycast(node.id, node.pos, next.pos, m_query.filter, 0, 0,
if (iresult.Succeeded()) out var rayHit);
if (status2.Succeeded())
{ {
path.AddRange(iresult.result.path); path.AddRange(rayHit.path);
} }
// raycast ends on poly boundary and the path might include the next poly boundary. // raycast ends on poly boundary and the path might include the next poly boundary.
@ -602,10 +603,11 @@ namespace DotRecast.Detour
DtNode next = m_nodePool.GetNodeAtIdx(node.pidx); DtNode next = m_nodePool.GetNodeAtIdx(node.pidx);
if ((node.flags & DtNode.DT_NODE_PARENT_DETACHED) != 0) if ((node.flags & DtNode.DT_NODE_PARENT_DETACHED) != 0)
{ {
Result<DtRaycastHit> iresult = Raycast(node.id, node.pos, next.pos, m_query.filter, 0, 0); var status2 = Raycast(node.id, node.pos, next.pos, m_query.filter, 0, 0,
if (iresult.Succeeded()) out var rayHit);
if (status2.Succeeded())
{ {
path.AddRange(iresult.result.path); path.AddRange(rayHit.path);
} }
// raycast ends on poly boundary and the path might include the next poly boundary. // raycast ends on poly boundary and the path might include the next poly boundary.

View File

@ -369,11 +369,11 @@ public class TestNavmeshTool : IRcTool
if (m_sposSet && m_eposSet && m_startRef != 0) if (m_sposSet && m_eposSet && m_startRef != 0)
{ {
{ {
Result<DtRaycastHit> hit = m_navQuery.Raycast(m_startRef, m_spos, m_epos, m_filter, 0, 0); var status = m_navQuery.Raycast(m_startRef, m_spos, m_epos, m_filter, 0, 0, out var rayHit);
if (hit.Succeeded()) if (status.Succeeded())
{ {
m_polys = hit.result.path; m_polys = rayHit.path;
if (hit.result.t > 1) if (rayHit.t > 1)
{ {
// No hit // No hit
m_hitPos = m_epos; m_hitPos = m_epos;
@ -382,15 +382,15 @@ public class TestNavmeshTool : IRcTool
else else
{ {
// Hit // Hit
m_hitPos = RcVec3f.Lerp(m_spos, m_epos, hit.result.t); m_hitPos = RcVec3f.Lerp(m_spos, m_epos, rayHit.t);
m_hitNormal = hit.result.hitNormal; m_hitNormal = rayHit.hitNormal;
m_hitResult = true; m_hitResult = true;
} }
// Adjust height. // Adjust height.
if (hit.result.path.Count > 0) if (rayHit.path.Count > 0)
{ {
var result = m_navQuery.GetPolyHeight(hit.result.path[hit.result.path.Count - 1], m_hitPos, out var h); var result = m_navQuery.GetPolyHeight(rayHit.path[rayHit.path.Count - 1], m_hitPos, out var h);
if (result.Succeeded()) if (result.Succeeded())
{ {
m_hitPos.y = h; m_hitPos.y = h;