From cc5ba4608f8a95b0087250c431ecbc7dace8d2bf Mon Sep 17 00:00:00 2001 From: "erwin.coumans" Date: Wed, 9 Sep 2009 23:23:22 +0000 Subject: [PATCH] use pre-tick callback to update motor targets in DynamicControlDemo: dynamicsWorld->setInternalTickCallback(callbackFunc,void* userPtr=MotorDemo,bool pretick=true --- Demos/DynamicControlDemo/MotorDemo.cpp | 35 +++++++++++++++++++++----- Demos/DynamicControlDemo/MotorDemo.h | 2 ++ 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/Demos/DynamicControlDemo/MotorDemo.cpp b/Demos/DynamicControlDemo/MotorDemo.cpp index a5042e840..674acc61c 100644 --- a/Demos/DynamicControlDemo/MotorDemo.cpp +++ b/Demos/DynamicControlDemo/MotorDemo.cpp @@ -243,7 +243,13 @@ public: +void motorPreTickCallback (btDynamicsWorld *world, btScalar timeStep) +{ + MotorDemo* motorDemo = (MotorDemo*)world->getWorldUserInfo(); + motorDemo->setMotorTargets(timeStep); + +} @@ -277,6 +283,8 @@ void MotorDemo::initPhysics() m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration); + m_dynamicsWorld->setInternalTickCallback(motorPreTickCallback,this,true); + // Setup a big ground box { @@ -304,12 +312,18 @@ void MotorDemo::spawnTestRig(const btVector3& startOffset, bool bFixed) m_rigs.push_back(rig); } -void MotorDemo::clientMoveAndDisplay() +void PreStep() { - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - //simple dynamics world doesn't handle fixed-time-stepping - float ms = getDeltaTimeMicroseconds(); +} + + + + +void MotorDemo::setMotorTargets(btScalar deltaTime) +{ + + float ms = deltaTime*1000000.; float minFPS = 1000000.f/60.f; if (ms > minFPS) ms = minFPS; @@ -335,11 +349,20 @@ void MotorDemo::clientMoveAndDisplay() } } + +} + +void MotorDemo::clientMoveAndDisplay() +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + //simple dynamics world doesn't handle fixed-time-stepping + float deltaTime = getDeltaTimeMicroseconds()/1000000.f; + if (m_dynamicsWorld) { - ///run the simulation at 120 hertz internally (maximum of 10 substeps) - m_dynamicsWorld->stepSimulation(ms / 1000000.f,10,1./120.f); + m_dynamicsWorld->stepSimulation(deltaTime); m_dynamicsWorld->debugDrawWorld(); } diff --git a/Demos/DynamicControlDemo/MotorDemo.h b/Demos/DynamicControlDemo/MotorDemo.h index 5ad65ac44..353b9e419 100644 --- a/Demos/DynamicControlDemo/MotorDemo.h +++ b/Demos/DynamicControlDemo/MotorDemo.h @@ -72,6 +72,8 @@ public: return demo; } + void setMotorTargets(btScalar deltaTime); + };