Skip to content

Commit

Permalink
Fix FatTriangleShape transformations
Browse files Browse the repository at this point in the history
  • Loading branch information
notgiven688 committed Aug 28, 2024
1 parent f2daac6 commit f1ddd92
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/Jitter2/Collision/Shapes/FatTriangleShape.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,22 @@ 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;

box.AddPoint(a);
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)
Expand Down Expand Up @@ -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;
}
}
3 changes: 3 additions & 0 deletions src/Jitter2/Collision/Shapes/TriangleMesh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ public struct Triangle
public int NeighborB;
public int NeighborC;

/// <summary>
/// The normalized normal of the triangle.
/// </summary>
public JVector Normal;

public Triangle(int a, int b, int c)
Expand Down

0 comments on commit f1ddd92

Please sign in to comment.