From 3bf9bb3b13521c8bba4d559f308c5b2c04973df8 Mon Sep 17 00:00:00 2001 From: Mitchell Stokes Date: Tue, 30 Oct 2012 15:44:16 +0000 Subject: BGE: Adding support for Bullet's collision masks. Each object now has a collision mask and a collision group. Object A and object B collide if object A's groups is in object B's mask and object B's group is in object A's mask. In other words, the group defines what the object is (collision wise) and the group defines what the object can collide with. The majority of this patch was provided by Kupoman with some edits from me and heavy testing by z0r. --- .../Physics/Bullet/CcdPhysicsEnvironment.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'source/gameengine/Physics/Bullet') diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp index e43ddb303e9..687fc116234 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp @@ -2208,10 +2208,29 @@ bool CcdOverlapFilterCallBack::needBroadphaseCollision(btBroadphaseProxy* proxy0 { btCollisionObject *colObj0, *colObj1; CcdPhysicsController *sensorCtrl, *objCtrl; + + KX_GameObject *kxObj0 = KX_GameObject::GetClientObject( + (KX_ClientObjectInfo*) + ((CcdPhysicsController*) + (((btCollisionObject*)proxy0->m_clientObject)->getUserPointer())) + ->getNewClientInfo()); + KX_GameObject *kxObj1 = KX_GameObject::GetClientObject( + (KX_ClientObjectInfo*) + ((CcdPhysicsController*) + (((btCollisionObject*)proxy1->m_clientObject)->getUserPointer())) + ->getNewClientInfo()); + + // First check the filters. Note that this is called during scene + // conversion, so we can't assume the KX_GameObject instances exist. This + // may make some objects erroneously collide on the first frame, but the + // alternative is to have them erroneously miss. bool collides; - // first check the filters collides = (proxy0->m_collisionFilterGroup & proxy1->m_collisionFilterMask) != 0; collides = collides && (proxy1->m_collisionFilterGroup & proxy0->m_collisionFilterMask); + if (kxObj0 && kxObj1) { + collides = collides && kxObj0->CheckCollision(kxObj1); + collides = collides && kxObj1->CheckCollision(kxObj0); + } if (!collides) return false; -- cgit v1.2.3