Si vous connaissez les types de forme que vous pouvez utiliser l'une des fonctions suivantes pour vérifier directement les chevauchements.
public static void Collision.CollideCircles(ref Manifold manifold,
CircleShape circle1, XForm xf1, CircleShape circle2, XForm xf2);
public static void Collision.CollidePolygonAndCircle(ref Manifold manifold,
PolygonShape polygon, XForm xf1, CircleShape circle, XForm xf2);
public static void Collision.CollideEdgeAndCircle(ref Manifold manifold,
EdgeShape edge, XForm transformA, CircleShape circle, XForm transformB);
public static void Collision.CollidePolyAndEdge(ref Manifold manifold,
PolygonShape polygon, XForm transformA, EdgeShape edge, XForm transformB);
public static void Collision.CollidePolygons(ref Manifold manifold,
PolygonShape polyA, XForm xfA, PolygonShape polyB, XForm xfB);
Ils prennent tous deux formes et deux transformations. Le résultat est un objet Manifold qui contient une collection de points où les limites de forme se croisent. Si le nombre de points est supérieur à zéro, vous avez une collision.
Vous pouvez obtenir les mêmes informations indirectement en mettant en œuvre l'interface ContactListener par une classe.
public class MyContactListener : ContactListener {
// Called when intersection begins.
void BeginContact(Contact contact) {
// ...
// Make some indication that the two bodies collide.
// ...
}
// Called when the intersection ends.
void EndContact(Contact contact) {
// ...
// Make some indication that the two bodies no longer collide.
// ...
}
// Called before the contact is processed by the dynamics solver.
void PreSolve(Contact contact, Manifold oldManifold) {}
// Called after the contact is processed by the dynamics solver.
void PostSolve(Contact contact, ContactImpulse impulse) {}
}
Les deux corps se trouvent interdiction de Contact._fixtureA.Body et Contact._fixtureB.Body. Vous devez enregistrer l'objet écouteur avec le monde.
GetFixtureList(), GetBodyList(), GetJointList(), etc. renvoyer le premier élément d'une liste chaînée. L'élément suivant de la liste est trouvé en appelant GetNext() sur l'élément. Vous pouvez parcourir la liste avec le code suivant. Lorsque GetNext() renvoie null, il n'y a plus d'éléments.
// Given there is a Body named body.
for (Fixture fix = body.GetFixtureList(); fix; fix = fix.GetNext()) {
// Operate on fix.
}