From f1ddd92b07f78929c157b7d977168284f8a68a44 Mon Sep 17 00:00:00 2001 From: notgiven688 Date: Wed, 28 Aug 2024 18:38:32 +0200 Subject: [PATCH] Fix FatTriangleShape transformations --- .../Collision/Shapes/FatTriangleShape.cs | 18 ++++++++++-------- src/Jitter2/Collision/Shapes/TriangleMesh.cs | 3 +++ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/Jitter2/Collision/Shapes/FatTriangleShape.cs b/src/Jitter2/Collision/Shapes/FatTriangleShape.cs index 3aa52942..92d13031 100644 --- a/src/Jitter2/Collision/Shapes/FatTriangleShape.cs +++ b/src/Jitter2/Collision/Shapes/FatTriangleShape.cs @@ -76,8 +76,9 @@ public override void CalculateBoundingBox(in JQuaternion orientation, in JVector JVector.Transform(a, orientation, out a); JVector.Transform(b, orientation, out b); JVector.Transform(c, orientation, out c); + JVector.Transform(triangle.Normal, orientation, out JVector delta); - JVector delta = JVector.Normalize((a - b) % (a - c)) * Thickness; + delta *= Thickness; box = JBBox.SmallBox; @@ -85,9 +86,12 @@ public override void CalculateBoundingBox(in JQuaternion orientation, in JVector box.AddPoint(b); box.AddPoint(c); - box.AddPoint(a + delta); - box.AddPoint(b + delta); - box.AddPoint(c + delta); + box.AddPoint(a - delta); + box.AddPoint(b - delta); + box.AddPoint(c - delta); + + box.Min += position; + box.Max += position; } public override void SupportMap(in JVector direction, out JVector result) @@ -116,9 +120,7 @@ public override void SupportMap(in JVector direction, out JVector result) result = c; } - JVector nnorm = (a - b) % (a - c); - - if (JVector.Dot(nnorm, direction) > 0.0f) - result += JVector.Normalize(nnorm) * Thickness; + if (JVector.Dot(triangle.Normal, direction) < 0.0f) + result -= triangle.Normal * Thickness; } } \ No newline at end of file diff --git a/src/Jitter2/Collision/Shapes/TriangleMesh.cs b/src/Jitter2/Collision/Shapes/TriangleMesh.cs index c72dbd0e..e7d35e7d 100644 --- a/src/Jitter2/Collision/Shapes/TriangleMesh.cs +++ b/src/Jitter2/Collision/Shapes/TriangleMesh.cs @@ -92,6 +92,9 @@ public struct Triangle public int NeighborB; public int NeighborC; + /// + /// The normalized normal of the triangle. + /// public JVector Normal; public Triangle(int a, int b, int c)