forked from mirror/DotRecast
remove nullable float in DtNavMeshRaycast.Raycast, RcPolyMeshRaycast.Raycast
This commit is contained in:
parent
ccba2afb0c
commit
912b9e27fb
|
@ -20,32 +20,32 @@ using DotRecast.Core;
|
|||
|
||||
namespace DotRecast.Detour
|
||||
{
|
||||
|
||||
/**
|
||||
* Simple helper to find an intersection between a ray and a nav mesh
|
||||
*/
|
||||
public static class DtNavMeshRaycast
|
||||
{
|
||||
public static float? Raycast(DtNavMesh mesh, RcVec3f src, RcVec3f dst)
|
||||
public static bool Raycast(DtNavMesh mesh, RcVec3f src, RcVec3f dst, out float hitTime)
|
||||
{
|
||||
hitTime = 0.0f;
|
||||
for (int t = 0; t < mesh.GetMaxTiles(); ++t)
|
||||
{
|
||||
DtMeshTile tile = mesh.GetTile(t);
|
||||
if (tile != null && tile.data != null)
|
||||
{
|
||||
float? intersection = Raycast(tile, src, dst);
|
||||
if (null != intersection)
|
||||
if (Raycast(tile, src, dst, out hitTime))
|
||||
{
|
||||
return intersection;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return false;
|
||||
}
|
||||
|
||||
private static float? Raycast(DtMeshTile tile, RcVec3f sp, RcVec3f sq)
|
||||
private static bool Raycast(DtMeshTile tile, RcVec3f sp, RcVec3f sq, out float hitTime)
|
||||
{
|
||||
hitTime = 0.0f;
|
||||
for (int i = 0; i < tile.data.header.polyCount; ++i)
|
||||
{
|
||||
DtPoly p = tile.data.polys[i];
|
||||
|
@ -79,9 +79,9 @@ namespace DotRecast.Detour
|
|||
}
|
||||
}
|
||||
|
||||
if (Intersections.IntersectSegmentTriangle(sp, sq, verts[0], verts[1], verts[2], out var intersection))
|
||||
if (Intersections.IntersectSegmentTriangle(sp, sq, verts[0], verts[1], verts[2], out hitTime))
|
||||
{
|
||||
return intersection;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ namespace DotRecast.Detour
|
|||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -770,20 +770,21 @@ public class RecastDemo : IRecastDemoChannel
|
|||
if (_sample == null)
|
||||
return;
|
||||
|
||||
float? hit = null;
|
||||
float hitTime = 0.0f;
|
||||
bool hit = false;
|
||||
if (inputGeom != null)
|
||||
{
|
||||
hit = inputGeom.RaycastMesh(rayStart, rayEnd);
|
||||
hit = inputGeom.RaycastMesh(rayStart, rayEnd, out hitTime);
|
||||
}
|
||||
|
||||
if (!hit.HasValue && _sample.GetNavMesh() != null)
|
||||
if (!hit && _sample.GetNavMesh() != null)
|
||||
{
|
||||
hit = DtNavMeshRaycast.Raycast(_sample.GetNavMesh(), rayStart, rayEnd);
|
||||
hit = DtNavMeshRaycast.Raycast(_sample.GetNavMesh(), rayStart, rayEnd, out hitTime);
|
||||
}
|
||||
|
||||
if (!hit.HasValue && _sample.GetRecastResults() != null)
|
||||
if (!hit && _sample.GetRecastResults() != null)
|
||||
{
|
||||
hit = RcPolyMeshRaycast.Raycast(_sample.GetRecastResults(), rayStart, rayEnd);
|
||||
hit = RcPolyMeshRaycast.Raycast(_sample.GetRecastResults(), rayStart, rayEnd, out hitTime);
|
||||
}
|
||||
|
||||
RcVec3f rayDir = RcVec3f.Of(rayEnd.x - rayStart.x, rayEnd.y - rayStart.y, rayEnd.z - rayStart.z);
|
||||
|
@ -795,9 +796,8 @@ public class RecastDemo : IRecastDemoChannel
|
|||
rayTool.HandleClickRay(rayStart, rayDir, processHitTestShift);
|
||||
}
|
||||
|
||||
if (hit.HasValue)
|
||||
if (hit)
|
||||
{
|
||||
float hitTime = hit.Value;
|
||||
if (0 != (_modState & KeyModState.Control))
|
||||
{
|
||||
// Marker
|
||||
|
|
|
@ -126,12 +126,14 @@ namespace DotRecast.Recast.DemoTool.Geom
|
|||
_offMeshConnections.RemoveAll(filter); // TODO : 확인 필요
|
||||
}
|
||||
|
||||
public float? RaycastMesh(RcVec3f src, RcVec3f dst)
|
||||
public bool RaycastMesh(RcVec3f src, RcVec3f dst, out float tmin)
|
||||
{
|
||||
tmin = 1.0f;
|
||||
|
||||
// Prune hit ray.
|
||||
if (!Intersections.IsectSegAABB(src, dst, bmin, bmax, out var btmin, out var btmax))
|
||||
{
|
||||
return null;
|
||||
return false;
|
||||
}
|
||||
|
||||
float[] p = new float[2];
|
||||
|
@ -144,10 +146,10 @@ namespace DotRecast.Recast.DemoTool.Geom
|
|||
List<RcChunkyTriMeshNode> chunks = _mesh.chunkyTriMesh.GetChunksOverlappingSegment(p, q);
|
||||
if (0 == chunks.Count)
|
||||
{
|
||||
return null;
|
||||
return false;
|
||||
}
|
||||
|
||||
float? tmin = 1.0f;
|
||||
tmin = 1.0f;
|
||||
bool hit = false;
|
||||
foreach (RcChunkyTriMeshNode chunk in chunks)
|
||||
{
|
||||
|
@ -181,9 +183,7 @@ namespace DotRecast.Recast.DemoTool.Geom
|
|||
}
|
||||
}
|
||||
|
||||
return hit
|
||||
? tmin
|
||||
: null;
|
||||
return hit;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -23,25 +23,26 @@ namespace DotRecast.Recast
|
|||
{
|
||||
public static class RcPolyMeshRaycast
|
||||
{
|
||||
public static float? Raycast(IList<RecastBuilderResult> results, RcVec3f src, RcVec3f dst)
|
||||
public static bool Raycast(IList<RecastBuilderResult> results, RcVec3f src, RcVec3f dst, out float hitTime)
|
||||
{
|
||||
hitTime = 0.0f;
|
||||
foreach (RecastBuilderResult result in results)
|
||||
{
|
||||
if (result.GetMeshDetail() != null)
|
||||
{
|
||||
float? intersection = Raycast(result.GetMesh(), result.GetMeshDetail(), src, dst);
|
||||
if (null != intersection)
|
||||
if (Raycast(result.GetMesh(), result.GetMeshDetail(), src, dst, out hitTime))
|
||||
{
|
||||
return intersection;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return false;
|
||||
}
|
||||
|
||||
private static float? Raycast(RcPolyMesh poly, RcPolyMeshDetail meshDetail, RcVec3f sp, RcVec3f sq)
|
||||
private static bool Raycast(RcPolyMesh poly, RcPolyMeshDetail meshDetail, RcVec3f sp, RcVec3f sq, out float hitTime)
|
||||
{
|
||||
hitTime = 0;
|
||||
if (meshDetail != null)
|
||||
{
|
||||
for (int i = 0; i < meshDetail.nmeshes; ++i)
|
||||
|
@ -62,9 +63,9 @@ namespace DotRecast.Recast
|
|||
vs[k].z = meshDetail.verts[verts + meshDetail.tris[tris + j * 4 + k] * 3 + 2];
|
||||
}
|
||||
|
||||
if (Intersections.IntersectSegmentTriangle(sp, sq, vs[0], vs[1], vs[2], out var intersection))
|
||||
if (Intersections.IntersectSegmentTriangle(sp, sq, vs[0], vs[1], vs[2], out hitTime))
|
||||
{
|
||||
return intersection;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -74,7 +75,7 @@ namespace DotRecast.Recast
|
|||
// TODO: check PolyMesh instead
|
||||
}
|
||||
|
||||
return null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue