forked from bit/DotRecastNetSim
remove nullable float in IntersectSegmentTriangle
This commit is contained in:
parent
8044b85ec5
commit
0614c040ba
|
@ -22,8 +22,9 @@ namespace DotRecast.Core
|
||||||
{
|
{
|
||||||
public static class Intersections
|
public static class Intersections
|
||||||
{
|
{
|
||||||
public static float? IntersectSegmentTriangle(RcVec3f sp, RcVec3f sq, RcVec3f a, RcVec3f b, RcVec3f c)
|
public static bool IntersectSegmentTriangle(RcVec3f sp, RcVec3f sq, RcVec3f a, RcVec3f b, RcVec3f c, out float t)
|
||||||
{
|
{
|
||||||
|
t = 0;
|
||||||
float v, w;
|
float v, w;
|
||||||
RcVec3f ab = b.Subtract(a);
|
RcVec3f ab = b.Subtract(a);
|
||||||
RcVec3f ac = c.Subtract(a);
|
RcVec3f ac = c.Subtract(a);
|
||||||
|
@ -38,22 +39,22 @@ namespace DotRecast.Core
|
||||||
float d = RcVec3f.Dot(qp, norm);
|
float d = RcVec3f.Dot(qp, norm);
|
||||||
if (d <= 0.0f)
|
if (d <= 0.0f)
|
||||||
{
|
{
|
||||||
return null;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute intersection t value of pq with plane of triangle. A ray
|
// Compute intersection t value of pq with plane of triangle. A ray
|
||||||
// intersects iff 0 <= t. Segment intersects iff 0 <= t <= 1. Delay
|
// intersects iff 0 <= t. Segment intersects iff 0 <= t <= 1. Delay
|
||||||
// dividing by d until intersection has been found to pierce triangle
|
// dividing by d until intersection has been found to pierce triangle
|
||||||
RcVec3f ap = sp.Subtract(a);
|
RcVec3f ap = sp.Subtract(a);
|
||||||
float t = RcVec3f.Dot(ap, norm);
|
t = RcVec3f.Dot(ap, norm);
|
||||||
if (t < 0.0f)
|
if (t < 0.0f)
|
||||||
{
|
{
|
||||||
return null;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (t > d)
|
if (t > d)
|
||||||
{
|
{
|
||||||
return null; // For segment; exclude this code line for a ray test
|
return false; // For segment; exclude this code line for a ray test
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute barycentric coordinate components and test if within bounds
|
// Compute barycentric coordinate components and test if within bounds
|
||||||
|
@ -61,19 +62,19 @@ namespace DotRecast.Core
|
||||||
v = RcVec3f.Dot(ac, e);
|
v = RcVec3f.Dot(ac, e);
|
||||||
if (v < 0.0f || v > d)
|
if (v < 0.0f || v > d)
|
||||||
{
|
{
|
||||||
return null;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
w = -RcVec3f.Dot(ab, e);
|
w = -RcVec3f.Dot(ab, e);
|
||||||
if (w < 0.0f || v + w > d)
|
if (w < 0.0f || v + w > d)
|
||||||
{
|
{
|
||||||
return null;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Segment/ray intersects triangle. Perform delayed division
|
// Segment/ray intersects triangle. Perform delayed division
|
||||||
t /= d;
|
t /= d;
|
||||||
|
|
||||||
return t;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsectSegAABB(RcVec3f sp, RcVec3f sq, RcVec3f amin, RcVec3f amax, out float tmin, out float tmax)
|
public static bool IsectSegAABB(RcVec3f sp, RcVec3f sq, RcVec3f amin, RcVec3f amax, out float tmin, out float tmax)
|
||||||
|
|
|
@ -79,8 +79,7 @@ namespace DotRecast.Detour
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float? intersection = Intersections.IntersectSegmentTriangle(sp, sq, verts[0], verts[1], verts[2]);
|
if (Intersections.IntersectSegmentTriangle(sp, sq, verts[0], verts[1], verts[2], out var intersection))
|
||||||
if (null != intersection)
|
|
||||||
{
|
{
|
||||||
return intersection;
|
return intersection;
|
||||||
}
|
}
|
||||||
|
|
|
@ -169,12 +169,11 @@ namespace DotRecast.Recast.DemoTool.Geom
|
||||||
vertices[tris[j + 2] * 3 + 1],
|
vertices[tris[j + 2] * 3 + 1],
|
||||||
vertices[tris[j + 2] * 3 + 2]
|
vertices[tris[j + 2] * 3 + 2]
|
||||||
);
|
);
|
||||||
float? t = Intersections.IntersectSegmentTriangle(src, dst, v1, v2, v3);
|
if (Intersections.IntersectSegmentTriangle(src, dst, v1, v2, v3, out var t))
|
||||||
if (null != t)
|
|
||||||
{
|
{
|
||||||
if (t.Value < tmin)
|
if (t < tmin)
|
||||||
{
|
{
|
||||||
tmin = t.Value;
|
tmin = t;
|
||||||
}
|
}
|
||||||
|
|
||||||
hit = true;
|
hit = true;
|
||||||
|
|
|
@ -21,7 +21,6 @@ using DotRecast.Core;
|
||||||
|
|
||||||
namespace DotRecast.Recast
|
namespace DotRecast.Recast
|
||||||
{
|
{
|
||||||
|
|
||||||
public static class PolyMeshRaycast
|
public static class PolyMeshRaycast
|
||||||
{
|
{
|
||||||
public static float? Raycast(IList<RecastBuilderResult> results, RcVec3f src, RcVec3f dst)
|
public static float? Raycast(IList<RecastBuilderResult> results, RcVec3f src, RcVec3f dst)
|
||||||
|
@ -63,8 +62,7 @@ namespace DotRecast.Recast
|
||||||
vs[k].z = meshDetail.verts[verts + meshDetail.tris[tris + j * 4 + k] * 3 + 2];
|
vs[k].z = meshDetail.verts[verts + meshDetail.tris[tris + j * 4 + k] * 3 + 2];
|
||||||
}
|
}
|
||||||
|
|
||||||
float? intersection = Intersections.IntersectSegmentTriangle(sp, sq, vs[0], vs[1], vs[2]);
|
if (Intersections.IntersectSegmentTriangle(sp, sq, vs[0], vs[1], vs[2], out var intersection))
|
||||||
if (null != intersection)
|
|
||||||
{
|
{
|
||||||
return intersection;
|
return intersection;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue