forked from mirror/DotRecast
change interface raycast
This commit is contained in:
parent
bf8d5f165d
commit
c3846198d1
|
@ -318,12 +318,12 @@ namespace DotRecast.Detour.Crowd
|
|||
var delta = next.Subtract(m_pos);
|
||||
RcVec3f goal = RcVec3f.Mad(m_pos, delta, pathOptimizationRange / dist);
|
||||
|
||||
Result<DtRaycastHit> rc = navquery.Raycast(m_path[0], m_pos, goal, filter, 0, 0);
|
||||
if (rc.Succeeded())
|
||||
var status = navquery.Raycast(m_path[0], m_pos, goal, filter, 0, 0, out var rayHit);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -927,17 +927,17 @@ namespace DotRecast.Detour
|
|||
List<long> shortcut = null;
|
||||
if (tryLOS)
|
||||
{
|
||||
Result<DtRaycastHit> rayHit = Raycast(parentRef, parentNode.pos, neighbourPos, filter,
|
||||
DT_RAYCAST_USE_COSTS, grandpaRef);
|
||||
if (rayHit.Succeeded())
|
||||
status = Raycast(parentRef, parentNode.pos, neighbourPos, filter,
|
||||
DT_RAYCAST_USE_COSTS, grandpaRef, out var rayHit);
|
||||
if (status.Succeeded())
|
||||
{
|
||||
foundShortCut = rayHit.result.t >= 1.0f;
|
||||
foundShortCut = rayHit.t >= 1.0f;
|
||||
if (foundShortCut)
|
||||
{
|
||||
shortcut = rayHit.result.path;
|
||||
shortcut = rayHit.path;
|
||||
// shortcut found using raycast. Using shorter cost
|
||||
// instead
|
||||
cost = parentNode.cost + rayHit.result.pathCost;
|
||||
cost = parentNode.cost + rayHit.pathCost;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1246,17 +1246,17 @@ namespace DotRecast.Detour
|
|||
List<long> shortcut = null;
|
||||
if (tryLOS)
|
||||
{
|
||||
Result<DtRaycastHit> rayHit = Raycast(parentRef, parentNode.pos, neighbourPos, m_query.filter,
|
||||
DT_RAYCAST_USE_COSTS, grandpaRef);
|
||||
if (rayHit.Succeeded())
|
||||
status = Raycast(parentRef, parentNode.pos, neighbourPos, m_query.filter,
|
||||
DT_RAYCAST_USE_COSTS, grandpaRef, out var rayHit);
|
||||
if (status.Succeeded())
|
||||
{
|
||||
foundShortCut = rayHit.result.t >= 1.0f;
|
||||
foundShortCut = rayHit.t >= 1.0f;
|
||||
if (foundShortCut)
|
||||
{
|
||||
shortcut = rayHit.result.path;
|
||||
shortcut = rayHit.path;
|
||||
// shortcut found using raycast. Using shorter cost
|
||||
// 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[in] maxPath The maximum number of polygons the @p path array can hold.
|
||||
/// @returns The status flags for the query.
|
||||
public Result<DtRaycastHit> Raycast(long startRef, RcVec3f startPos, RcVec3f endPos, IDtQueryFilter filter, int options,
|
||||
long prevRef)
|
||||
public DtStatus Raycast(long startRef, RcVec3f startPos, RcVec3f endPos, IDtQueryFilter filter, int options,
|
||||
long prevRef, out DtRaycastHit hit)
|
||||
{
|
||||
hit = null;
|
||||
|
||||
// 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)))
|
||||
{
|
||||
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];
|
||||
|
||||
|
@ -2235,7 +2238,7 @@ namespace DotRecast.Detour
|
|||
if (!iresult.intersects)
|
||||
{
|
||||
// Could not hit the polygon, keep the old t and report hit.
|
||||
return Results.Success(hit);
|
||||
return DtStatus.DT_SUCCSESS;
|
||||
}
|
||||
|
||||
hit.hitEdgeIndex = iresult.segMax;
|
||||
|
@ -2261,7 +2264,7 @@ namespace DotRecast.Detour
|
|||
curRef, tile, poly);
|
||||
}
|
||||
|
||||
return Results.Success(hit);
|
||||
return DtStatus.DT_SUCCSESS;
|
||||
}
|
||||
|
||||
// Follow neighbours.
|
||||
|
@ -2390,7 +2393,7 @@ namespace DotRecast.Detour
|
|||
hit.hitNormal.y = 0;
|
||||
hit.hitNormal.z = -dx;
|
||||
hit.hitNormal.Normalize();
|
||||
return Results.Success(hit);
|
||||
return DtStatus.DT_SUCCSESS;
|
||||
}
|
||||
|
||||
// No hit, advance to neighbour polygon.
|
||||
|
@ -2402,7 +2405,7 @@ namespace DotRecast.Detour
|
|||
poly = nextPoly;
|
||||
}
|
||||
|
||||
return Results.Success(hit);
|
||||
return DtStatus.DT_SUCCSESS;
|
||||
}
|
||||
|
||||
/// @par
|
||||
|
|
|
@ -361,16 +361,16 @@ namespace DotRecast.Detour
|
|||
bool foundShortCut = false;
|
||||
if (tryLOS)
|
||||
{
|
||||
Result<DtRaycastHit> rayHit = Raycast(parentRef, parentNode.pos, neighbourNode.pos, m_query.filter,
|
||||
DT_RAYCAST_USE_COSTS, grandpaRef);
|
||||
if (rayHit.Succeeded())
|
||||
status = Raycast(parentRef, parentNode.pos, neighbourNode.pos, m_query.filter,
|
||||
DT_RAYCAST_USE_COSTS, grandpaRef, out var rayHit);
|
||||
if (status.Succeeded())
|
||||
{
|
||||
foundShortCut = rayHit.result.t >= 1.0f;
|
||||
foundShortCut = rayHit.t >= 1.0f;
|
||||
if (foundShortCut)
|
||||
{
|
||||
// shortcut found using raycast. Using shorter cost
|
||||
// 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);
|
||||
if ((node.flags & DtNode.DT_NODE_PARENT_DETACHED) != 0)
|
||||
{
|
||||
Result<DtRaycastHit> iresult = Raycast(node.id, node.pos, next.pos, m_query.filter, 0, 0);
|
||||
if (iresult.Succeeded())
|
||||
var status2 = Raycast(node.id, node.pos, next.pos, m_query.filter, 0, 0,
|
||||
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.
|
||||
|
@ -602,10 +603,11 @@ namespace DotRecast.Detour
|
|||
DtNode next = m_nodePool.GetNodeAtIdx(node.pidx);
|
||||
if ((node.flags & DtNode.DT_NODE_PARENT_DETACHED) != 0)
|
||||
{
|
||||
Result<DtRaycastHit> iresult = Raycast(node.id, node.pos, next.pos, m_query.filter, 0, 0);
|
||||
if (iresult.Succeeded())
|
||||
var status2 = Raycast(node.id, node.pos, next.pos, m_query.filter, 0, 0,
|
||||
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.
|
||||
|
|
|
@ -369,11 +369,11 @@ public class TestNavmeshTool : IRcTool
|
|||
if (m_sposSet && m_eposSet && m_startRef != 0)
|
||||
{
|
||||
{
|
||||
Result<DtRaycastHit> hit = m_navQuery.Raycast(m_startRef, m_spos, m_epos, m_filter, 0, 0);
|
||||
if (hit.Succeeded())
|
||||
var status = m_navQuery.Raycast(m_startRef, m_spos, m_epos, m_filter, 0, 0, out var rayHit);
|
||||
if (status.Succeeded())
|
||||
{
|
||||
m_polys = hit.result.path;
|
||||
if (hit.result.t > 1)
|
||||
m_polys = rayHit.path;
|
||||
if (rayHit.t > 1)
|
||||
{
|
||||
// No hit
|
||||
m_hitPos = m_epos;
|
||||
|
@ -382,15 +382,15 @@ public class TestNavmeshTool : IRcTool
|
|||
else
|
||||
{
|
||||
// Hit
|
||||
m_hitPos = RcVec3f.Lerp(m_spos, m_epos, hit.result.t);
|
||||
m_hitNormal = hit.result.hitNormal;
|
||||
m_hitPos = RcVec3f.Lerp(m_spos, m_epos, rayHit.t);
|
||||
m_hitNormal = rayHit.hitNormal;
|
||||
m_hitResult = true;
|
||||
}
|
||||
|
||||
// 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())
|
||||
{
|
||||
m_hitPos.y = h;
|
||||
|
|
Loading…
Reference in New Issue