title: Bullet physics with OpenGL
body: <p>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:</p>
  
  <pre><code>void CGL::initPhysics( void ) {
  broadphase = new btDbvtBroadphase();
  collisionConfiguration = new btDefaultCollisionConfiguration();
  dispatcher = new btCollisionDispatcher(collisionConfiguration);
  solver = new btSequentialImpulseConstraintSolver;
  dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,broadphase,solver,collisionConfiguration);
  
  dynamicsWorld-&gt;setGravity(btVector3(0,-10,0));
  
  
  ballShape = new btSphereShape(1);
  pinShape = new btCylinderShape(btVector3(1,1,1));
  pinShape-&gt;setMargin(0.04);
  
  fallMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,10,0)));
  btScalar mass = 1;
  btVector3 fallInertia(0,0,0);
  ballShape-&gt;calculateLocalInertia(mass,fallInertia);
  
  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);
  dynamicsWorld-&gt;addRigidBody(groundRigidBody);
  
  btRigidBody::btRigidBodyConstructionInfo fallRigidBodyCI(mass,fallMotionState,ballShape,fallInertia);
  btRigidBody* fallRigidBody = new btRigidBody(fallRigidBodyCI);
  dynamicsWorld-&gt;addRigidBody(fallRigidBody);
  
  for (int i=0 ; i&lt;300 ; i++) {
      dynamicsWorld-&gt;stepSimulation(1/60.f,10);
  
      btTransform trans;
      fallRigidBody-&gt;getMotionState()-&gt;getWorldTransform(trans);
  
      fallY = trans.getOrigin().getY();
  }
  state_list.remove( STATE_FALL_BALL );
  printf("stoped\n");
  </code></pre>
  
  <p>}</p>
  
  <p>And the drawing function which is called at the beginning looks like this:</p>
  
  <pre><code>void CGL::fallingBall( void ) {
  glPushMatrix();
  
  float colBall2[4] = { 0.0f, 0.0f, 1.0f, 1.0f };
  glMaterialfv( GL_FRONT, GL_AMBIENT, colBall2);
  
  glTranslatef(0.0f,fallY,0.0f);
  
  printf("fallY: %f\n",fallY);
  
  glutSolidSphere(1.0f,20,20);
  
  glPopMatrix();
  </code></pre>
  
  <p>}</p>
  
  <p>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.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>This is changed function and loop. Gathering all the info I supose it should now work but it doesn't. It doesn't draw anything.</p>
  
  <pre><code>initPhysics(){
      for (int i=0 ; i&lt;500 ; i++) 
      {
          draw();
  
      }
      state_list.remove( STATE_FALL_BALL );
      printf("stoped\n");
  }
  
  void CGL::draw(void)
  {
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
              current_time = getTime();
              since_update = current_time - last_update;
              printf("time: %f\n",since_update);
              if(since_update&gt;timestep)
              {
                  dynamicsWorld-&gt;stepSimulation(timestep,10);
                  last_update = current_time;
              }
              btTransform trans;
              fallRigidBody-&gt;getMotionState()-&gt;getWorldTransform(trans);
  
              fallY = trans.getOrigin().getY();
              fallingBall();
              printf("fallY: %f\n",fallY);
  glFlush();
      }
  </code></pre>
  
  <p>And beginning variable declaratins look like that:</p>
  
  <pre><code>last_update = 0;
  timestep = 100;
  current_time = 0;
  since_update = 0;
  </code></pre>