シェイプ タイプがわかっている場合は、次の関数のいずれかを使用してオーバーラップを直接チェックできます。
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);
それらはすべて 2 つの形状と 2 つの変換をとります。結果は、形状の境界が交差するポイントのコレクションを含む Manifold オブジェクトです。ポイントの数が 0 より大きい場合、衝突があります。
ContactListener インターフェースをクラスで実装することで、間接的に同じ情報を取得することができます。
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) {}
}
2 つのボディは、Contact._fixtureA.Body と Contact._fixtureB.Body から見つけることができます。リスナー オブジェクトを World に登録する必要があります。
GetFixtureList()、GetBodyList()、GetJointList() などは、リンクされたリストの最初の要素を返します。リスト内の次の要素は、要素で GetNext() を呼び出すことによって検出されます。次のコードを使用して、リストを反復処理できます。GetNext() が null を返す場合、それ以上要素はありません。
// Given there is a Body named body.
for (Fixture fix = body.GetFixtureList(); fix; fix = fix.GetNext()) {
// Operate on fix.
}