summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Franke <arnfranke@yahoo.com>2019-10-08 22:47:22 -0400
committerAaron Franke <arnfranke@yahoo.com>2019-10-08 22:47:22 -0400
commit643874f8caff3a284a70bf4c114cca9f165deea2 (patch)
tree1fa30fc5d7f2b7e18a34817a7f5890315b46a2d1
parentbb41f0b0cbc8ceff55a77cec42664c2ee81bb2f2 (diff)
[Mono] Change Plane intersect methods to return nullable Vector3
-rw-r--r--core/math/plane.cpp2
-rw-r--r--modules/mono/glue/Managed/Files/Plane.cs23
2 files changed, 13 insertions, 12 deletions
diff --git a/core/math/plane.cpp b/core/math/plane.cpp
index b01853c4ac..b6bcac4b27 100644
--- a/core/math/plane.cpp
+++ b/core/math/plane.cpp
@@ -91,7 +91,7 @@ bool Plane::intersect_3(const Plane &p_plane1, const Plane &p_plane2, Vector3 *r
real_t denom = vec3_cross(normal0, normal1).dot(normal2);
- if (ABS(denom) <= CMP_EPSILON)
+ if (Math::is_zero_approx(denom))
return false;
if (r_result) {
diff --git a/modules/mono/glue/Managed/Files/Plane.cs b/modules/mono/glue/Managed/Files/Plane.cs
index a13161d2e6..26e717e089 100644
--- a/modules/mono/glue/Managed/Files/Plane.cs
+++ b/modules/mono/glue/Managed/Files/Plane.cs
@@ -82,12 +82,12 @@ namespace Godot
return Mathf.Abs(dist) <= epsilon;
}
- public Vector3 Intersect3(Plane b, Plane c)
+ public Vector3? Intersect3(Plane b, Plane c)
{
real_t denom = _normal.Cross(b._normal).Dot(c._normal);
- if (Mathf.Abs(denom) <= Mathf.Epsilon)
- return new Vector3();
+ if (Mathf.IsZeroApprox(denom))
+ return null;
Vector3 result = b._normal.Cross(c._normal) * D +
c._normal.Cross(_normal) * b.D +
@@ -96,34 +96,35 @@ namespace Godot
return result / denom;
}
- public Vector3 IntersectRay(Vector3 from, Vector3 dir)
+ public Vector3? IntersectRay(Vector3 from, Vector3 dir)
{
real_t den = _normal.Dot(dir);
- if (Mathf.Abs(den) <= Mathf.Epsilon)
- return new Vector3();
+ if (Mathf.IsZeroApprox(den))
+ return null;
real_t dist = (_normal.Dot(from) - D) / den;
// This is a ray, before the emitting pos (from) does not exist
if (dist > Mathf.Epsilon)
- return new Vector3();
+ return null;
return from + dir * -dist;
}
- public Vector3 IntersectSegment(Vector3 begin, Vector3 end)
+ public Vector3? IntersectSegment(Vector3 begin, Vector3 end)
{
Vector3 segment = begin - end;
real_t den = _normal.Dot(segment);
- if (Mathf.Abs(den) <= Mathf.Epsilon)
- return new Vector3();
+ if (Mathf.IsZeroApprox(den))
+ return null;
real_t dist = (_normal.Dot(begin) - D) / den;
+ // Only allow dist to be in the range of 0 to 1, with tolerance.
if (dist < -Mathf.Epsilon || dist > 1.0f + Mathf.Epsilon)
- return new Vector3();
+ return null;
return begin + segment * -dist;
}