From 221aee7ecdb352f87e6baae87061fbfc05e8f819 Mon Sep 17 00:00:00 2001 From: Porteries Tristan Date: Fri, 3 Jul 2015 11:13:47 +0200 Subject: BGE: Fix T45278 sleeping deactivation with overlay scene. this commit fix also angular and linear threshold sleeping value update via bge.constraints. --- .../Physics/Bullet/CcdPhysicsEnvironment.cpp | 35 +++++++++++++++++----- 1 file changed, 28 insertions(+), 7 deletions(-) (limited to 'source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp') diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp index 9b2a83c3e67..71a603fc747 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp @@ -410,6 +410,10 @@ m_ccdMode(0), m_solverType(-1), m_profileTimings(0), m_enableSatCollisionDetection(false), +m_deactivationTime(2.0f), +m_linearDeactivationThreshold(0.8f), +m_angularDeactivationThreshold(1.0f), +m_contactBreakingThreshold(0.02f), m_solver(NULL), m_ownPairCache(NULL), m_filterCallback(NULL), @@ -472,8 +476,10 @@ void CcdPhysicsEnvironment::AddCcdPhysicsController(CcdPhysicsController* ctrl) //this m_userPointer is just used for triggers, see CallbackTriggers obj->setUserPointer(ctrl); - if (body) - body->setGravity( m_gravity ); + if (body) { + body->setGravity(m_gravity); + body->setSleepingThresholds(m_linearDeactivationThreshold, m_angularDeactivationThreshold); + } if (body) { @@ -699,6 +705,10 @@ bool CcdPhysicsEnvironment::ProceedDeltaTime(double curTime,float timeStep,float std::set::iterator it; int i; + // Update Bullet global variables. + gDeactivationTime = m_deactivationTime; + gContactBreakingThreshold = m_contactBreakingThreshold; + for (it=m_controllers.begin(); it!=m_controllers.end(); it++) { (*it)->SynchronizeMotionStates(timeStep); @@ -918,21 +928,32 @@ void CcdPhysicsEnvironment::SetNumIterations(int numIter) } void CcdPhysicsEnvironment::SetDeactivationTime(float dTime) { - gDeactivationTime = dTime; + m_deactivationTime = dTime; } void CcdPhysicsEnvironment::SetDeactivationLinearTreshold(float linTresh) { - gLinearSleepingTreshold = linTresh; + m_linearDeactivationThreshold = linTresh; + + // Update from all controllers. + for (std::set::iterator it = m_controllers.begin(); it != m_controllers.end(); it++) { + if ((*it)->GetRigidBody()) + (*it)->GetRigidBody()->setSleepingThresholds(m_linearDeactivationThreshold, m_angularDeactivationThreshold); + } } void CcdPhysicsEnvironment::SetDeactivationAngularTreshold(float angTresh) { - gAngularSleepingTreshold = angTresh; + m_angularDeactivationThreshold = angTresh; + + // Update from all controllers. + for (std::set::iterator it = m_controllers.begin(); it != m_controllers.end(); it++) { + if ((*it)->GetRigidBody()) + (*it)->GetRigidBody()->setSleepingThresholds(m_linearDeactivationThreshold, m_angularDeactivationThreshold); + } } void CcdPhysicsEnvironment::SetContactBreakingTreshold(float contactBreakingTreshold) { - gContactBreakingThreshold = contactBreakingTreshold; - + m_contactBreakingThreshold = contactBreakingTreshold; } -- cgit v1.2.3