From 2a0d95aa0dd1bdd196168eeb5a79a40539eff5a2 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 22 Oct 2024 20:01:28 +0300 Subject: [PATCH] Update gjkepa.cs OpenTK library support. --- gjkepa.cs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/gjkepa.cs b/gjkepa.cs index 9205866..a0ae45a 100644 --- a/gjkepa.cs +++ b/gjkepa.cs @@ -1,6 +1,12 @@ +#define OpenTK //Define using OpenTK here + using System; using System.Collections.Generic; +#if OpenTK +using OpenTK.Mathematics; +#else using System.Numerics; +#endif using System.Linq; /// @@ -381,7 +387,13 @@ private static (List, int) GetFaceNormals(List polytope, Vector3 c = polytope[faces[i + 2]].Point; Vector3 normal = Vector3.Cross(b - a, c - a); - float l = normal.Length(); + + #if OpenTK + float l = normal.Length; //For OpenTK.Mathematics + #else + float l = normal.Length(); //For System.Numeric + #endif + float distance = float.MaxValue; //If vectors is colliniar we have degenerate face @@ -539,7 +551,7 @@ private static int EPA(Vector3[] polyhedron1, Vector3[] polyhedron2, Simplex sim } -#if GJKEPA_DEBUG +#if GJKEPA_DEBUG /* DrawPolytope(polytope, faces); UInt32 clr = 4294901760u; // Red @@ -601,10 +613,12 @@ public static (float u, float v, float w) GetBarycentricCoordinates(Vector3 p, V float denom = d00 * d11 - d01 * d01; // Check for a zero denominator before division + /* if (Math.Abs(denom) <= Epsilon) { + // For future it could be processed throw new InvalidOperationException("Cannot compute barycentric coordinates for a degenerate triangle."); - } + }*/ // Compute barycentric coordinates float v = (d11 * d20 - d01 * d21) / denom;