모양 유형을 알고있는 경우 다음 기능 중 하나를 사용하여 겹침 여부를 직접 확인할 수 있습니다.
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);
이들 모두는 두 개의 모양과 두 개의 변환을 사용합니다. 결과는 모양 경계가 교차하는 점들의 집합을 포함하는 매니 폴드 객체입니다. 포인트 수가 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) {}
}
두 신체는 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.
}