From 912b9e27fb9972a09f274d7fbcd5b3823cc66f3b Mon Sep 17 00:00:00 2001 From: ikpil Date: Tue, 1 Aug 2023 23:32:28 +0900 Subject: [PATCH] remove nullable float in DtNavMeshRaycast.Raycast, RcPolyMeshRaycast.Raycast --- src/DotRecast.Detour/DtNavMeshRaycast.cs | 22 +++++++++---------- src/DotRecast.Recast.Demo/RecastDemo.cs | 16 +++++++------- .../Geom/DemoInputGeomProvider.cs | 14 ++++++------ src/DotRecast.Recast/RcPolyMeshRaycast.cs | 19 ++++++++-------- 4 files changed, 36 insertions(+), 35 deletions(-) diff --git a/src/DotRecast.Detour/DtNavMeshRaycast.cs b/src/DotRecast.Detour/DtNavMeshRaycast.cs index 040391b..1796953 100644 --- a/src/DotRecast.Detour/DtNavMeshRaycast.cs +++ b/src/DotRecast.Detour/DtNavMeshRaycast.cs @@ -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; } } -} +} \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/RecastDemo.cs b/src/DotRecast.Recast.Demo/RecastDemo.cs index f25613f..56bd94d 100644 --- a/src/DotRecast.Recast.Demo/RecastDemo.cs +++ b/src/DotRecast.Recast.Demo/RecastDemo.cs @@ -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 diff --git a/src/DotRecast.Recast.DemoTool/Geom/DemoInputGeomProvider.cs b/src/DotRecast.Recast.DemoTool/Geom/DemoInputGeomProvider.cs index 21292bf..f677b7b 100644 --- a/src/DotRecast.Recast.DemoTool/Geom/DemoInputGeomProvider.cs +++ b/src/DotRecast.Recast.DemoTool/Geom/DemoInputGeomProvider.cs @@ -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 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; } diff --git a/src/DotRecast.Recast/RcPolyMeshRaycast.cs b/src/DotRecast.Recast/RcPolyMeshRaycast.cs index 9736df3..60b5d1e 100644 --- a/src/DotRecast.Recast/RcPolyMeshRaycast.cs +++ b/src/DotRecast.Recast/RcPolyMeshRaycast.cs @@ -23,25 +23,26 @@ namespace DotRecast.Recast { public static class RcPolyMeshRaycast { - public static float? Raycast(IList results, RcVec3f src, RcVec3f dst) + public static bool Raycast(IList 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; } } } \ No newline at end of file