I’m using Box2dx (ported to C#; optimized for XNA). It handles collision resolution, but how can I tell if two objects are currently colliding?
This is the function I’m trying to write:
public bool IsColliding(GameObjectController collider1, GameObjectController collider2)
Where collider1.Model.Body is the Box2d Body, and collider1.Model.BodyDef is the Box2d BodyDef. (The same goes for collider2, of course.)
UPDATE: Looks like contact listeners or this could be useful:
AABB collisionBox;
model.Body.GetFixtureList().GetAABB(out collisionBox);
Why does GetFixtureList() return one fixture?
If you know the shape types you can use any of the following functions to directly check for overlap.
They all take two shapes and two transforms. The result is a Manifold object which contains a collection of points where the shape boundaries intersect. If the number of points is greater than zero you have a collision.
You can get the same information indirectly by implementing the ContactListener interface by a class.
The two bodies ban be found from Contact._fixtureA.Body and Contact._fixtureB.Body. You have to register the listener object with the World.
GetFixtureList(), GetBodyList(), GetJointList(), etc. return the first element in a linked list. The next element in the list is found by calling GetNext() on the element. You can iterate over the list with the following code. When GetNext() returns null there are no more elements.