diff options
Diffstat (limited to 'source/gameengine')
-rw-r--r-- | source/gameengine/Ketsji/KX_GameObject.cpp | 13 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_GameObject.h | 11 | ||||
-rw-r--r-- | source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp | 8 |
3 files changed, 32 insertions, 0 deletions
diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index 04a806dfd92..5b8d5fbfe1f 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -481,6 +481,19 @@ void KX_GameObject::ActivateGraphicController(bool recurse) } } +void KX_GameObject::SetUserCollisionGroup(short group) +{ + m_userCollisionGroup = group; +} +void KX_GameObject::SetUserCollisionMask(short mask) +{ + m_userCollisionMask = mask; +} + +bool KX_GameObject::CheckCollision(KX_GameObject* other) +{ + return this->m_userCollisionGroup & other->m_userCollisionMask; +} CValue* KX_GameObject::GetReplica() { diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h index 2b0d13ff2f7..569a4a2b2a1 100644 --- a/source/gameengine/Ketsji/KX_GameObject.h +++ b/source/gameengine/Ketsji/KX_GameObject.h @@ -98,6 +98,10 @@ protected: bool m_bIsNegativeScaling; MT_Vector4 m_objectColor; + // Bit fields for user control over physics collisions + short m_userCollisionGroup; + short m_userCollisionMask; + // visible = user setting // culled = while rendering, depending on camera bool m_bVisible; @@ -464,6 +468,13 @@ public: * @add/remove the graphic controller to the physic system */ void ActivateGraphicController(bool recurse); + + void SetUserCollisionGroup(short filter); + void SetUserCollisionMask(short mask); + /** + * Extra broadphase check for user controllable collisions + */ + bool CheckCollision(KX_GameObject *other); /** * \section Coordinate system manipulation functions diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp index 5d28bf47401..49652ef9544 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp @@ -2214,11 +2214,19 @@ void CcdPhysicsEnvironment::CallbackTriggers() bool CcdOverlapFilterCallBack::needBroadphaseCollision(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1) const { btCollisionObject *colObj0, *colObj1; + KX_GameObject *gameObj0 = KX_GameObject::GetClientObject((KX_ClientObjectInfo*)((CcdPhysicsController*)((btCollisionObject*)proxy0->m_clientObject)->getUserPointer())->getNewClientInfo()); + KX_GameObject *gameObj1 = KX_GameObject::GetClientObject((KX_ClientObjectInfo*)((CcdPhysicsController*)((btCollisionObject*)proxy1->m_clientObject)->getUserPointer())->getNewClientInfo()); CcdPhysicsController *sensorCtrl, *objCtrl; + bool collides; // first check the filters collides = (proxy0->m_collisionFilterGroup & proxy1->m_collisionFilterMask) != 0; collides = collides && (proxy1->m_collisionFilterGroup & proxy0->m_collisionFilterMask); + if (gameObj0 && gameObj1) + { + collides = collides && gameObj0->CheckCollision(gameObj1); + collides = collides && gameObj1->CheckCollision(gameObj0); + } if (!collides) return false; |