Skip to content

Commit

Permalink
Update gjkepa.cs
Browse files Browse the repository at this point in the history
OpenTK library support.
  • Loading branch information
exatb committed Oct 22, 2024
1 parent cc8010c commit 2a0d95a
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions gjkepa.cs
Original file line number Diff line number Diff line change
@@ -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;

/// <summary>
Expand Down Expand Up @@ -381,7 +387,13 @@ private static (List<Vector4>, int) GetFaceNormals(List<SupportPoint> 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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 2a0d95a

Please sign in to comment.