My physics simulation runs like a slow motion movie, here are some samples:
https://youtu.be/P8C59huuz5M
https://www.youtube.com/watch?v=u-8Bw3w45R4
It's like the action takes place on the Moon.
I use version bullet-2.81-rev2613.
I have a workaround to this problem by simply multiplying by some number (6,8,10) the elapsed seconds value in the stepSimulation function,
so instead of this:
Code: Select all
mDynamicsWorld->stepSimulation(static_cast<btScalar>(frameTimer.getElapsedSeconds()), 10);
Code: Select all
mDynamicsWorld->stepSimulation(static_cast<btScalar>(frameTimer.getElapsedSeconds())*10.0f, 10);
Based on the topics in the forum, I think I might have problem around, my main loop (it's based on the Bullett Canonical Loop example)
or the world scale (though I think I am in the proper limits). Gravity as Y -10 should work.
Can't see the forest for the trees, so if anybody could have look on the setup,
and point out anything would be most welcome.
Here is extract of the setup which i think is important:
Code: Select all
//setup of dynamics world
mBroadPhase = new btDbvtBroadphase();
mCollisionConfiguration = new btDefaultCollisionConfiguration();
mDispatcher = new btCollisionDispatcher( mCollisionConfiguration );
mSolver = new btSequentialImpulseConstraintSolver;
mDynamicsWorld = new btDiscreteDynamicsWorld( mDispatcher, mBroadPhase, mSolver, mCollisionConfiguration );
mDynamicsWorld->setGravity( btVector3( 0.0f, -10.0f, 0.0f ) );
Code: Select all
//the main loop
while (!done)
{
...
static cTimer frameTimer;
mDynamicsWorld->stepSimulation(static_cast<btScalar>(frameTimer.getElapsedSeconds()),10);
frameTimer.reset();
...
renderFrame();
...
}
0.0161584
0.0161978
0.0163978
0.016127
0.0164509
0.0158099
0.0161158
0.0163459
0.0160278
0.0172848
0.0151219
0.0162947
0.0164883
0.0157126
0.0165123
0.0159632
0.0165696
0.0160042
0.0159603
0.0158954
Code: Select all
//the rigid body dimensions are like this:
falling boxes:
btVector(5,5,5) //in other words a box is 10 units wide, 10 units tall, and 10 units deep
Code: Select all
//transformation of meshes
//I use btMotionState to get interpolated values, and use it to transform meshes:
static btTransform trans;
static_cast<btRigidBody*>(mRigidBody)->getMotionState()->getWorldTransform(trans);
trans.getOpenGLMatrix((btScalar*)glm::value_ptr(transformation));
Code: Select all
//rigid bodies are setup like this
cRigidBody::cRigidBody(const glm::vec3& translation, const glm::quat& orientation, const std::shared_ptr<cHull> parentHull, cPhysicsWorld& dynamicsWorld)
{
if (parentHull->mMass > 0)
{
mMotionState = new btDefaultMotionState(btTransform(btQuaternion(orientation.x, orientation.y, orientation.z, orientation.w),
btVector3(translation.x, translation.y, translation.z)));
btVector3 btInertia = btVector3((btScalar)parentHull->mInertia.x, (btScalar)parentHull->mInertia.y, (btScalar)parentHull->mInertia.z);
parentHull->getCollisionShape()->calculateLocalInertia((btScalar)parentHull->mMass, btInertia);
btRigidBody::btRigidBodyConstructionInfo rigidBodyConstructionInfo((btScalar)parentHull->mMass, mMotionState, parentHull->getCollisionShape(), btInertia);
mRigidBody = new btRigidBody(rigidBodyConstructionInfo);
mRigidBody->setFriction(parentHull->mFriction);
static_cast<btRigidBody*>(mRigidBody)->setAngularFactor(btVector3(parentHull->mAngularVelocity.x, parentHull->mAngularVelocity.y, parentHull->mAngularVelocity.z));
dynamicsWorld.getPhysicsWorld()->addRigidBody(static_cast<btRigidBody*>(mRigidBody));
}
...
}