queryAABB method

  1. @override
List<PhysicsBody> queryAABB(
  1. Rect rect
)
override

Return all active bodies whose bounding box — round all their shapes, turned with the body — overlaps rect. The native backend answers with Box2D's boxes, which it keeps a little larger than the shapes (by a tenth of a metre), so a body just outside rect can come too.

Implementation

@override
List<PhysicsBody> queryAABB(Rect rect) {
  if (!_nativeReady) return super.queryAABB(rect);

  _ensureQueryBuffers();
  int count;
  do {
    count = box2d.b2w_queryAABB(
      _world!.handle,
      rect.left,
      rect.top,
      rect.right,
      rect.bottom,
      _allCategories,
      _allCategories,
      _queryBodyBuffer!,
      _queryCapacity,
    );
  } while (_queryFull(count));

  final result = <PhysicsBody>[];
  for (var i = 0; i < count; i++) {
    final body = _handleToBody[_queryBodyBuffer![i]];
    if (body != null) result.add(body);
  }
  return result;
}