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 lowerBound = aabb.lowerBound;
  final upperBound = aabb.upperBound;
  final xfq = xf.q;

  final v1x = (xfq.cos * vertex1.x - xfq.sin * vertex1.y) + xf.p.x;
  final v1y = (xfq.sin * vertex1.x + xfq.cos * vertex1.y) + xf.p.y;
  final v2x = (xfq.cos * vertex2.x - xfq.sin * vertex2.y) + xf.p.x;
  final v2y = (xfq.sin * vertex2.x + xfq.cos * vertex2.y) + xf.p.y;

  lowerBound.x = v1x < v2x ? v1x : v2x;
  lowerBound.y = v1y < v2y ? v1y : v2y;
  upperBound.x = v1x > v2x ? v1x : v2x;
  upperBound.y = v1y > v2y ? v1y : v2y;

  lowerBound.x -= radius;
  lowerBound.y -= radius;
  upperBound.x += radius;
  upperBound.y += radius;
}