I've read and re-read the wiki information about DynamicsWorld->stepSimulation() and I'm still having problems with jerky object movement and really need some help.
I init my rigidBody like this:
Code: Select all
// create the dynamic body
mBody = new btRigidBody(btScalar(mass), motionState, mShape, localInertia);
// disable deactivation for this player object
mBody->setActivationState(DISABLE_DEACTIVATION);
Code: Select all
mBody->applyCentralImpulse(btVector3(0, 0, 1));Code: Select all
// deltaTime is elapsed time between ticks
mDynamicsWorld->stepSimulation((btScalar)(deltaTime * 0.001f), 10);
// sleep a random amount so our framerate is NEVER constant
// I'm doing this to exaggerate the issue as much as possible
// bullet should be able to cope with any framerate within reason
double rand = Math::Rand() / RAND_MAX;
// this sleep value max is 100 ms so the minimum fps should be 10 fps which
// our substeps of 10 should handle OK
Sleep(rand * 100.0);
Code: Select all
virtual void setWorldTransform(const btTransform& centerOfMassWorldTrans)
{
m_graphicsWorldTrans = centerOfMassWorldTrans * m_centerOfMassOffset;
btQuaternion rot = m_graphicsWorldTrans.getRotation();
btVector3 pos = m_graphicsWorldTrans.getOrigin();
Vector3 currentPosition(pos.x(), pos.y(), pos.z());
// this time is set RIGHT before we call stepSimulation()
double currentTime = PhysicsManagerBullet::getSingletonPtr()->getLastTickTime();
if(currentTime - mLastDebugTime > 1000.0) {
double distance = currentPosition.distance(mLastPosition);
double elapsedTime = currentTime - mLastDebugTime;
double speed = distance / elapsedTime;
mLastDebugTime = currentTime;
mLastPosition = currentPosition;
std::cout << "Speed " << speed << " Distance " << distance << " Elapsed Time " << elapsedTime << std::endl;
}
}
Code: Select all
Speed 0.00966792 Distance 9.72162 Elapsed Time 1005.55
Speed 0.0103209 Distance 10.7008 Elapsed Time 1036.81
Speed 0.00967697 Distance 10.0042 Elapsed Time 1033.82
Speed 0.0101613 Distance 10.4589 Elapsed Time 1029.29
Speed 0.0103201 Distance 10.726 Elapsed Time 1039.33
Speed 0.00967133 Distance 9.82541 Elapsed Time 1015.93
Speed 0.00983295 Distance 9.84683 Elapsed Time 1001.41
Speed 0.0103265 Distance 10.5231 Elapsed Time 1019.04
Speed 0.0101602 Distance 10.5283 Elapsed Time 1036.22
Speed 0.00968169 Distance 10.1577 Elapsed Time 1049.16
Speed 0.0101633 Distance 10.3325 Elapsed Time 1016.65
Speed 0.0104901 Distance 10.6877 Elapsed Time 1018.84
Should I query the position of the rigidBody manually instead of using a motion state object?
Any help is MUCH appreciated!