computeAABB method

  1. @override
void computeAABB(
  1. AABB aabb,
  2. Transform xf,
  3. int childIndex
)
override

Given a transform, compute the associated axis aligned bounding box for a child shape.

Implementation

@override
void computeAABB(AABB aabb, Transform xf, int childIndex) {
  final lower = aabb.lowerBound;
  final upper = aabb.upperBound;
  final v1 = vertices[0];
  final xfqc = xf.q.cos;
  final xfqs = xf.q.sin;
  final xfpx = xf.p.x;
  final xfpy = xf.p.y;
  lower.x = (xfqc * v1.x - xfqs * v1.y) + xfpx;
  lower.y = (xfqs * v1.x + xfqc * v1.y) + xfpy;
  upper.x = lower.x;
  upper.y = lower.y;

  for (var i = 1; i < vertices.length; ++i) {
    final v2 = vertices[i];
    // Vec2 v = Mul(xf, _vertices[i]);
    final vx = (xfqc * v2.x - xfqs * v2.y) + xfpx;
    final vy = (xfqs * v2.x + xfqc * v2.y) + xfpy;
    lower.x = lower.x < vx ? lower.x : vx;
    lower.y = lower.y < vy ? lower.y : vy;
    upper.x = upper.x > vx ? upper.x : vx;
    upper.y = upper.y > vy ? upper.y : vy;
  }

  lower.x -= radius;
  lower.y -= radius;
  upper.x += radius;
  upper.y += radius;
}