Meh, decided that creating a derived custom world was the way to go.
Code: Select all
// Custom world that overrides stepSimulation for applications that implement their own fixed time step calculations
class btFixedWorld : public btDiscreteDynamicsWorld {
public:
btFixedWorld(btDispatcher *dispatcher, btBroadphaseInterface *pairCache, btConstraintSolver *constraintSolver, btCollisionConfiguration *collisionConfiguration)
: btDiscreteDynamicsWorld(dispatcher, pairCache, constraintSolver, collisionConfiguration) { }
~btFixedWorld() { }
void setTimeStepRemainder(btScalar time) { m_localTime = time; }
int stepSimulation(btScalar timeStep, int maxSubSteps=0, btScalar fixedTimeStep=0) {
saveKinematicState(timeStep);
applyGravity();
internalSingleStepSimulation(timeStep);
clearForces();
return 1;
}
};
Then, in your application's update code, something like this would work:
Code: Select all
// Accumulate time and apply fixed timestep
TimeStepAccumulator += FrameTime;
while(TimeStepAccumulator >= TimeStep) {
Update(TimeStep); // update game logic and call stepSimulation(TimeStep)
TimeStepAccumulator -= TimeStep;
}
World->setTimeStepRemainder(TimeStepAccumulator);
World->synchronizeMotionStates();
Buttery smooth interpolation ensues.