From d283167614c28ee67818c767b533005d04ed173e Mon Sep 17 00:00:00 2001 From: notgiven688 Date: Thu, 3 Oct 2024 00:25:44 +0200 Subject: [PATCH] Separating case: closest triangle normal not equal to collision normal --- src/GJKEPA.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/GJKEPA.cs b/src/GJKEPA.cs index 187dbf4..a307852 100644 --- a/src/GJKEPA.cs +++ b/src/GJKEPA.cs @@ -398,7 +398,8 @@ public bool Solve(out JVector point1, out JVector point2, out JVector normal, ou point1 = bc.X * VerticesA[ctri.A] + bc.Y * VerticesA[ctri.B] + bc.Z * VerticesA[ctri.C]; point2 = bc.X * VerticesB[ctri.A] + bc.Y * VerticesB[ctri.B] + bc.Z * VerticesB[ctri.C]; - normal = ctri.Normal * (1.0d / Math.Sqrt(ctri.NormalSq)); + if (Math.Abs(separation) > NumericEpsilon) normal = -ctri.ClosestToOrigin * (1.0f / separation); + else normal = ctri.Normal * (1.0f / Math.Sqrt(ctri.NormalSq)); return true; }