satForAxes method

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

Implementation

bool satForAxes(List<double> axes, Vector3 v0, Vector3 v1, Vector3 v2, Vector3 extents) {
  Vector3 _testAxis = Vector3.zero();
  for (int i = 0, j = axes.length - 3; i <= j; i += 3) {
    _testAxis.copyFromArray(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(p0, math.max(p1, p2)), math.min(p0, math.min(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;
}