Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSybren A. Stüvel <sybren@stuvel.eu>2015-06-18 15:43:30 +0300
committerSybren A. Stüvel <sybren@stuvel.eu>2015-06-28 13:54:53 +0300
commitc5c2883ce039a35945282b770ad77f461cdf05ad (patch)
treed0a363da2847f3aecaf4e49d15484aa269c20d73 /source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
parent32319dd106970663d1b78bb25048b3ceccffc01a (diff)
BGE Fix: apply velocity clamping on every physics subtick
This patch uses the Bullet "internal tick callback" functionality to ensure that velocity clamping is performed after every physics update. This makes a difference when physics subticks > 1, as in that case the too-high velocity could have impacted the simulation. This patch follows the examples at [1] and [2]; the latter example also explains that the way we limit velocity in the BGE (before this patch) is wrong. [1] http://bulletphysics.org/mediawiki-1.5.8/index.php/Simulation_Tick_Callbacks [2] http://www.bulletphysics.org/mediawiki-1.5.8/index.php/Code_Snippets#I_want_to_cap_the_speed_of_my_spaceship; Reviewed by: panzergame Differential Revision: https://developer.blender.org/D1364
Diffstat (limited to 'source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp')
-rw-r--r--source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
index 89c8c124bc8..14a19fdfb41 100644
--- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
+++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
@@ -452,6 +452,7 @@ m_scalingPropagated(false)
SetSolverType(1);//issues with quickstep and memory allocations
// m_dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,m_broadphase,m_solver,m_collisionConfiguration);
m_dynamicsWorld = new btSoftRigidDynamicsWorld(dispatcher,m_broadphase,m_solver,m_collisionConfiguration);
+ m_dynamicsWorld->setInternalTickCallback(&CcdPhysicsEnvironment::StaticSimulationSubtickCallback, this);
//m_dynamicsWorld->getSolverInfo().m_linearSlop = 0.01f;
//m_dynamicsWorld->getSolverInfo().m_solverMode= SOLVER_USE_WARMSTARTING + SOLVER_USE_2_FRICTION_DIRECTIONS + SOLVER_RANDMIZE_ORDER + SOLVER_USE_FRICTION_WARMSTARTING;
@@ -677,6 +678,22 @@ void CcdPhysicsEnvironment::DebugDrawWorld()
m_dynamicsWorld->debugDrawWorld();
}
+void CcdPhysicsEnvironment::StaticSimulationSubtickCallback(btDynamicsWorld *world, btScalar timeStep)
+{
+ // Get the pointer to the CcdPhysicsEnvironment associated with this Bullet world.
+ CcdPhysicsEnvironment *this_ = static_cast<CcdPhysicsEnvironment*>(world->getWorldUserInfo());
+ this_->SimulationSubtickCallback(timeStep);
+}
+
+void CcdPhysicsEnvironment::SimulationSubtickCallback(btScalar timeStep)
+{
+ std::set<CcdPhysicsController*>::iterator it;
+
+ for (it = m_controllers.begin(); it != m_controllers.end(); it++) {
+ (*it)->SimulationTick(timeStep);
+ }
+}
+
bool CcdPhysicsEnvironment::ProceedDeltaTime(double curTime,float timeStep,float interval)
{
std::set<CcdPhysicsController*>::iterator it;