computeAabb method

  1. @protected
void computeAabb(
  1. Aabb2 aabb
)

Computes the axis-aligned bounding box for this hitbox.

Subclasses can override this to provide a tighter AABB. The default implementation uses the absolute scaled size and rotation.

Implementation

@protected
void computeAabb(Aabb2 aabb) {
  final size = absoluteScaledSize;
  // This has double.minPositive since a point on the edge of the AABB is
  // currently counted as outside.
  _halfExtents.setValues(
    size.x / 2 + _extentEpsilon,
    size.y / 2 + _extentEpsilon,
  );
  _rotationMatrix.setRotationZ(absoluteAngle);
  aabb
    ..setCenterAndHalfExtents(absoluteCenter, _halfExtents)
    ..rotate(_rotationMatrix);
}