I have got some problem implementing bullet physics into my opengl game. The thing is that it doesn't want to update my translatef value continously but only at the end. The code for bullet looks like this:

void CGL::initPhysics( void ) {
broadphase = new btDbvtBroadphase();
collisionConfiguration = new btDefaultCollisionConfiguration();
dispatcher = new btCollisionDispatcher(collisionConfiguration);
solver = new btSequentialImpulseConstraintSolver;
dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,broadphase,solver,collisionConfiguration);


ballShape = new btSphereShape(1);
pinShape = new btCylinderShape(btVector3(1,1,1));

fallMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,10,0)));
btScalar mass = 1;
btVector3 fallInertia(0,0,0);

btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0,1,0),1);

btDefaultMotionState* groundMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,-1,0)));
btRigidBody::btRigidBodyConstructionInfo groundRigidBodyCI(0,groundMotionState,groundShape,btVector3(0,0,0));
btRigidBody* groundRigidBody = new btRigidBody(groundRigidBodyCI);

btRigidBody::btRigidBodyConstructionInfo fallRigidBodyCI(mass,fallMotionState,ballShape,fallInertia);
btRigidBody* fallRigidBody = new btRigidBody(fallRigidBodyCI);

for (int i=0 ; i<300 ; i++) {

    btTransform trans;

    fallY = trans.getOrigin().getY();
state_list.remove( STATE_FALL_BALL );


And the drawing function which is called at the beginning looks like this:

void CGL::fallingBall( void ) {

float colBall2[4] = { 0.0f, 0.0f, 1.0f, 1.0f };
glMaterialfv( GL_FRONT, GL_AMBIENT, colBall2);


printf("fallY: %f\n",fallY);




The thing is that it shows correct value in this function's printf but translation is called only at the beginning I mean I can only see the last state.

Can anyone help me, please?


1 Answer 1


Your code doesn't magically connect the values in the physics simulation to the graphics. You have to have a loop which both steps the simulation and redraws the scene with the updated positions.

I can't show you specific code to do this because you haven't shown where CGL::fallingBall is called, but if you're using an existing framework (are you?) then you're abusing it by running the simulation inside a function called “initPhysics” — you should do only the setup there, and find the main loop/callback and put your stepSimulation there.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .