Changeset View
Changeset View
Standalone View
Standalone View
source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
| Show First 20 Lines • Show All 2,245 Lines • ▼ Show 20 Lines | bool CcdPhysicsEnvironment::RequestCollisionCallback(PHY_IPhysicsController* ctrl) | ||||
| if (!ccdCtrl->Register()) | if (!ccdCtrl->Register()) | ||||
| return false; | return false; | ||||
| m_triggerControllers.insert(ccdCtrl); | m_triggerControllers.insert(ccdCtrl); | ||||
| return true; | return true; | ||||
| } | } | ||||
| void CcdPhysicsEnvironment::CallbackTriggers() | void CcdPhysicsEnvironment::CallbackTriggers() | ||||
| { | { | ||||
| if (m_triggerCallbacks[PHY_OBJECT_RESPONSE] || (m_debugDrawer && (m_debugDrawer->getDebugMode() & btIDebugDraw::DBG_DrawContactPoints))) | bool draw_contact_points = m_debugDrawer && (m_debugDrawer->getDebugMode() & btIDebugDraw::DBG_DrawContactPoints); | ||||
| { | if (!m_triggerCallbacks[PHY_OBJECT_RESPONSE] && !draw_contact_points) | ||||
| return; | |||||
| //walk over all overlapping pairs, and if one of the involved bodies is registered for trigger callback, perform callback | //walk over all overlapping pairs, and if one of the involved bodies is registered for trigger callback, perform callback | ||||
| btDispatcher* dispatcher = m_dynamicsWorld->getDispatcher(); | btDispatcher* dispatcher = m_dynamicsWorld->getDispatcher(); | ||||
| int numManifolds = dispatcher->getNumManifolds(); | int numManifolds = dispatcher->getNumManifolds(); | ||||
| for (int i=0;i<numManifolds;i++) | for (int i=0;i<numManifolds;i++) | ||||
| { | { | ||||
| btPersistentManifold* manifold = dispatcher->getManifoldByIndexInternal(i); | btPersistentManifold* manifold = dispatcher->getManifoldByIndexInternal(i); | ||||
| int numContacts = manifold->getNumContacts(); | int numContacts = manifold->getNumContacts(); | ||||
| if (numContacts) | if (numContacts == 0) continue; | ||||
| { | |||||
| const btRigidBody* rb0 = static_cast<const btRigidBody*>(manifold->getBody0()); | const btRigidBody* rb0 = static_cast<const btRigidBody*>(manifold->getBody0()); | ||||
| const btRigidBody* rb1 = static_cast<const btRigidBody*>(manifold->getBody1()); | const btRigidBody* rb1 = static_cast<const btRigidBody*>(manifold->getBody1()); | ||||
| if (m_debugDrawer && (m_debugDrawer->getDebugMode() & btIDebugDraw::DBG_DrawContactPoints)) | |||||
| if (draw_contact_points) | |||||
| { | { | ||||
| for (int j=0;j<numContacts;j++) | for (int j=0;j<numContacts;j++) | ||||
| { | { | ||||
| btVector3 color(1,0,0); | btVector3 color(1,1,0); | ||||
| const btManifoldPoint& cp = manifold->getContactPoint(j); | const btManifoldPoint& cp = manifold->getContactPoint(j); | ||||
| if (m_debugDrawer) | m_debugDrawer->drawContactPoint(cp.m_positionWorldOnB, cp.m_normalWorldOnB, | ||||
| m_debugDrawer->drawContactPoint(cp.m_positionWorldOnB,cp.m_normalWorldOnB,cp.getDistance(),cp.getLifeTime(),color); | cp.getDistance(), cp.getLifeTime(), color); | ||||
| } | } | ||||
| } | } | ||||
| const btRigidBody* obj0 = rb0; | |||||
| const btRigidBody* obj1 = rb1; | |||||
| //m_internalOwner is set in 'addPhysicsController' | //m_internalOwner is set in 'addPhysicsController' | ||||
| CcdPhysicsController* ctrl0 = static_cast<CcdPhysicsController*>(obj0->getUserPointer()); | CcdPhysicsController* ctrl0 = static_cast<CcdPhysicsController*>(rb0->getUserPointer()); | ||||
| CcdPhysicsController* ctrl1 = static_cast<CcdPhysicsController*>(obj1->getUserPointer()); | CcdPhysicsController* ctrl1 = static_cast<CcdPhysicsController*>(rb1->getUserPointer()); | ||||
| std::set<CcdPhysicsController*>::const_iterator i = m_triggerControllers.find(ctrl0); | std::set<CcdPhysicsController*>::const_iterator iter = m_triggerControllers.find(ctrl0); | ||||
| if (i == m_triggerControllers.end()) | if (iter == m_triggerControllers.end()) | ||||
| { | { | ||||
| i = m_triggerControllers.find(ctrl1); | iter = m_triggerControllers.find(ctrl1); | ||||
| } | } | ||||
| if (!(i == m_triggerControllers.end())) | if (iter != m_triggerControllers.end()) | ||||
| { | { | ||||
| m_triggerCallbacks[PHY_OBJECT_RESPONSE](m_triggerCallbacksUserPtrs[PHY_OBJECT_RESPONSE], | m_triggerCallbacks[PHY_OBJECT_RESPONSE](m_triggerCallbacksUserPtrs[PHY_OBJECT_RESPONSE], | ||||
| ctrl0,ctrl1,0); | ctrl0,ctrl1,0); | ||||
| } | } | ||||
| // Bullet does not refresh the manifold contact point for object without contact response | // Bullet does not refresh the manifold contact point for object without contact response | ||||
| // may need to remove this when a newer Bullet version is integrated | // may need to remove this when a newer Bullet version is integrated | ||||
| if (!dispatcher->needsResponse(rb0, rb1)) | if (!dispatcher->needsResponse(rb0, rb1)) | ||||
| { | { | ||||
| // Refresh algorithm fails sometimes when there is penetration | // Refresh algorithm fails sometimes when there is penetration | ||||
| // (usuall the case with ghost and sensor objects) | // (usuall the case with ghost and sensor objects) | ||||
| // Let's just clear the manifold, in any case, it is recomputed on each frame. | // Let's just clear the manifold, in any case, it is recomputed on each frame. | ||||
| manifold->clearManifold(); //refreshContactPoints(rb0->getCenterOfMassTransform(),rb1->getCenterOfMassTransform()); | manifold->clearManifold(); //refreshContactPoints(rb0->getCenterOfMassTransform(),rb1->getCenterOfMassTransform()); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | |||||
| } | |||||
| // This call back is called before a pair is added in the cache | // This call back is called before a pair is added in the cache | ||||
| // Handy to remove objects that must be ignored by sensors | // Handy to remove objects that must be ignored by sensors | ||||
| bool CcdOverlapFilterCallBack::needBroadphaseCollision(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1) const | bool CcdOverlapFilterCallBack::needBroadphaseCollision(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1) const | ||||
| { | { | ||||
| btCollisionObject *colObj0, *colObj1; | btCollisionObject *colObj0, *colObj1; | ||||
| CcdPhysicsController *sensorCtrl, *objCtrl; | CcdPhysicsController *sensorCtrl, *objCtrl; | ||||
| KX_GameObject *kxObj0 = KX_GameObject::GetClientObject( | KX_GameObject *kxObj0 = KX_GameObject::GetClientObject( | ||||
| ▲ Show 20 Lines • Show All 672 Lines • ▼ Show 20 Lines | struct BlenderDebugDraw : public btIDebugDraw | ||||
| virtual void reportErrorWarning(const char* warningString) | virtual void reportErrorWarning(const char* warningString) | ||||
| { | { | ||||
| } | } | ||||
| virtual void drawContactPoint(const btVector3& PointOnB,const btVector3& normalOnB,float distance,int lifeTime,const btVector3& color) | virtual void drawContactPoint(const btVector3& PointOnB,const btVector3& normalOnB,float distance,int lifeTime,const btVector3& color) | ||||
| { | { | ||||
| //not yet | drawLine(PointOnB, PointOnB + normalOnB, color); | ||||
| drawSphere(PointOnB, 0.1, color); | |||||
| } | } | ||||
| virtual void setDebugMode(int debugMode) | virtual void setDebugMode(int debugMode) | ||||
| { | { | ||||
| m_debugMode = debugMode; | m_debugMode = debugMode; | ||||
| } | } | ||||
| virtual int getDebugMode() const | virtual int getDebugMode() const | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 548 Lines • Show Last 20 Lines | |||||