Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7027247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:13:21+00:00 2026-05-28T00:13:21+00:00

I have got some problem implementing bullet physics into my opengl game. The thing

  • 0

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);

dynamicsWorld->setGravity(btVector3(0,-10,0));


ballShape = new btSphereShape(1);
pinShape = new btCylinderShape(btVector3(1,1,1));
pinShape->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->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->addRigidBody(groundRigidBody);

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

for (int i=0 ; i<300 ; i++) {
    dynamicsWorld->stepSimulation(1/60.f,10);

    btTransform trans;
    fallRigidBody->getMotionState()->getWorldTransform(trans);

    fallY = trans.getOrigin().getY();
}
state_list.remove( STATE_FALL_BALL );
printf("stoped\n");

}

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

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();

}

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.

EDIT

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.

initPhysics(){
    for (int i=0 ; i<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>timestep)
            {
                dynamicsWorld->stepSimulation(timestep,10);
                last_update = current_time;
            }
            btTransform trans;
            fallRigidBody->getMotionState()->getWorldTransform(trans);

            fallY = trans.getOrigin().getY();
            fallingBall();
            printf("fallY: %f\n",fallY);
glFlush();
    }

And beginning variable declaratins look like that:

last_update = 0;
timestep = 100;
current_time = 0;
since_update = 0;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:13:22+00:00Added an answer on May 28, 2026 at 12:13 am

    That looks a little disorganized. I guess the basic mistake to remedy the immediate problem without delving into multithreading would be to do something like this:

    //pseudo-code to get the idea
    void draw(){
        // clear Buffers and setup matricies
        ....
        //calculate the time that has pased since the last time that the physics have been calculated
        time_t current_time = getCurrentTime();
        time_t since_update = current_time - last_update;
    
        //if enough time has passed since the last redraw calculate physics
        if(since_update>timestep)
        {
            dynamicsWorld->stepSimulation(timestep,10);
            last_update = current_time;
        }
        btTransform trans;
        fallRigidBody->getMotionState()->getWorldTransform(trans);
    
        fallY = trans.getOrigin().getY();
    
        //draw various object
        ....
        fallingBall();
        //swap buffers or flush()
        glSwapBuffers();
    }
    

    Unless there is a distinct reason for using OpenGL directly I’d suggest that you use a higher level toolkit. Also the usual disclaimer that you are currently using an old version of OpenGL.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have got some problem on implementing Django sessions. I have an employee listing
I have some problem with Jquery Autocomplete plugin ( http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/ ) I got it
I've got some Columns in a DataGridView that have their Binding property set to
I have got a piece of code, that should countdown some number (in this
I've got some problem, I have list of data in the file: 053-37878 03828008
I have got some code to pass in a variable into a script from
I have some problem to get the Google Analytics to work. I have got
I have got a serious problem running our web app in some machines.. machines
i have a problem, I got some li, inside them i have a link
I have got a problem with multi line data (data that contains newline \n).

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.