I can write an example demonstrating this, but from what I've seen of the new API, it's still not possible to test shape-shape overlap easily. There are a few other "pure geometry" questions that it would be nice if Box2D could answer for free shapes as well as fixed ones, now that free shapes exist.
I'd really like to see the following code work:
Code:
bool f(b2AABB aabb,b2Shape* shape, b2Transform xf){
b2PolygonShape poly;
aabb.GetPolygonShape(poly);//Simple wrapper for SetAsBox
return shape->TestShape(xf, &poly, b2Identity);
}
I would need both of these functions before I could truly answer the OPs query without any real boiler plate, or any shape type switching.
(TestShape would virtual dispatch based on the two types, and call through to the b2Collide* set of functions, similar to how Box2D works internally, just without requiring a contact or fixture. I could produce a draft).
Still, in the interest of being useful, here is a completely untested STL example that gathers unique bodies, without precise testing:
Code:
struct UniqueBodies : public b2QueryCallback
{
UniqueBodies(std::set<b2Body*>& bodies):bodies(bodies){}
std::set<b2Body*>& bodies;
void ReportFixture(b2Fixture* fixture)
{
bodies.insert(fixture->GetBody());
}
}
void AddUniqueBodies(b2World* world, const b2AABB& aabb, std::set<b2Body*>& bodies)
{
UniqueBodies callback(bodies);
world->Query(&callback, aabb);
}
I'd say that's decently short, this is C++ not python.