Bullet Simulation Freezes
Posted: Sat Mar 31, 2018 7:22 pm
Hello,
The attached file is an example of SDL2 and Bullet -2.81.
The bullet part in there is made from a simple example found in the Wiki pages.
The cube in there is falling down on a ground plane, that is all. But when I start the application the cube is sometimes already on the ground, the fall is not even seen and sometimes, the simulation freezes completely and the cube just hangs in the air and stays there.
In the function bullet_cyclic() I limit the time difference d to 50 ms, so I don't see a reason that the simulation would be too fast. It should rather be going slower. The reason for limiting d is that I have read that stepSimulation must be called densely enough.
I wonder if you see any reason why the simulation should be freezing?
Best regards
Torsten
The attached file is an example of SDL2 and Bullet -2.81.
The bullet part in there is made from a simple example found in the Wiki pages.
Code: Select all
void init_bullet(void) {
broadphase = new btDbvtBroadphase();
collisionConfiguration = new btDefaultCollisionConfiguration();
dispatcher = new btCollisionDispatcher(collisionConfiguration);
solver = new btSequentialImpulseConstraintSolver;
dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration);
dynamicsWorld->setGravity(btVector3(0, 0, -10));
groundShape = new btStaticPlaneShape(btVector3(0, 0, 1), 1);
// fallShape = new btSphereShape(1);
fallShape = new btBoxShape(btVector3(0.5, 0.5, 0.5));
groundMotionState = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(0, 0, -1)));
//btRigidBody::btRigidBodyConstructionInfo
// groundRigidBodyCI(0, groundMotionState, groundShape, btVector3(0, 0, 0));
groundRigidBodyCI = new btRigidBody::btRigidBodyConstructionInfo(0, groundMotionState, groundShape, btVector3(0, 0, 0));
groundRigidBody = new btRigidBody(*groundRigidBodyCI);
dynamicsWorld->addRigidBody(groundRigidBody);
fallMotionState = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(0, 0, 5)));
btScalar mass = 1;
btVector3 fallInertia(0, 0, 0);
fallShape->calculateLocalInertia(mass, fallInertia);
fallRigidBodyCI = new btRigidBody::btRigidBodyConstructionInfo(mass, fallMotionState, fallShape, fallInertia);
fallRigidBody = new btRigidBody(*fallRigidBodyCI);
dynamicsWorld->addRigidBody(fallRigidBody);
}
void bullet_cyclic(Uint32 d) {
if(d > 50) {
d = 50;
}
dynamicsWorld->stepSimulation(1.0f / d, 500);
}
In the function bullet_cyclic() I limit the time difference d to 50 ms, so I don't see a reason that the simulation would be too fast. It should rather be going slower. The reason for limiting d is that I have read that stepSimulation must be called densely enough.
I wonder if you see any reason why the simulation should be freezing?
Best regards
Torsten