satForAxes<T extends num> method

bool satForAxes<T extends num>(
  1. List<T> axes,
  2. Vector3 v0,
  3. Vector3 v1,
  4. Vector3 v2,
  5. Vector3 extents,
)

Implementation

bool satForAxes<T extends num>(
    List<T> axes, Vector3 v0, Vector3 v1, Vector3 v2, Vector3 extents) {
  for (int i = 0, j = axes.length - 3; i <= j; i += 3) {
    _testAxis.copyFromUnknown(axes, i);
    // project the aabb onto the seperating axis
    final r = extents.x * (_testAxis.x).abs() +
        extents.y * (_testAxis.y).abs() +
        extents.z * (_testAxis.z).abs();
    // project all 3 vertices of the triangle onto the seperating axis
    final p0 = v0.dot(_testAxis);
    final p1 = v1.dot(_testAxis);
    final p2 = v2.dot(_testAxis);
    // actual test, basically see if either of the most extreme of the triangle points intersects r
    if (math.max(-math.max(math.max(p0, p1), p2), math.min(math.min(p0, p1), p2)) > r) {
      // points of the projected triangle are outside the projected half-length of the aabb
      // the axis is seperating and we can exit
      return false;
    }
  }

  return true;
}