Bullet physics with OpenGL

  • Bullet physics with OpenGL sebap123

    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?

  • 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.

opengl c++ bullet-physics
Related questions and answers
  • (); node-&gt;attachObject(ent); btTransform Transform; Transform.setIdentity(); Transform.setOrigin(btVector3(0,1,0)); // Give it to the motion state btDefaultMotionState *MotionState = new btDefaultMotionState(Transform); btCollisionShape *Shape = new btStaticPlaneShape(btVector3(0,1,0),0); // Add Mass btVector3 LocalInertia; Shape-&gt;calculateLocalInertia(0, LocalInertia); // CReate the rigid body object btRigidBody *RigidBody = new btRigidBody(0, MotionState, Shape, LocalInertia); // Store a pointer to the Ogre Node so we can update it later RigidBody-&gt;setUserPointer((void

  • ) initialization: dynamicsWorld-&gt;setGravity(btVector3(0,-10,0)); ballShape = new btSphereShape(1); fallMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(2,1,0))); btScalar mass = 5; btVector3 fallInertia(0,0,0); ballShape-&gt;calculateLocalInertia(mass,fallInertia); groundShape = new btBoxShape(btVector3(btScalar(50.),btScalar(1.),btScalar(70.))); btDefaultMotionState* groundMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,-1,0))); btRigidBody::btRigidBodyConstructionInfo groundRigidBodyCI

  • btDefaultMotionState(btTransform(btQuaternion(0,0,0,0),btVector3(x,y,z))); btScalar Mass = 1; btVector3 FallInertia(0,0,0); btRigidBody::btRigidBodyConstructionInfo StillRigidCI(Mass,StillStateMOT,shape,FallInertia); btRigidBody *ContiRigid = new btRigidBody(StillRigidCI); PhysicsWorld-&gt;addRigidBody(ContiRigid); Edit 1: btScalar Mass = 1; btVector3 FallInertia(0,0,0... = new btRigidBody(StillRigidCI); PhysicsWorld-&gt;addRigidBody(ContiRigid); Edit 2: There is no need to create the bullet vertices on the heap with new: btVector3 v0( p0[0], p0[1], p0[2

  • I want to create an object than only moves along the the X and Z axes, while keeping the Y-axis disabled (it's like movement in 2D, and the object wont fall down). I'm currently using a 6 dof constraint to restrict movement in the Y-axis, but it's not working: btRigidBody* zeroBody = new btRigidBody(0, NULL, NULL); // Create the body that we attach things to btRigidBody* robot = mCarChassis-&gt;getBulletRigidBody(); btGeneric6DofConstraint* constrict = new btGeneric6DofConstraint(*robot, *zeroBody, btTransform::getIdentity(), btTransform::getIdentity(), false); constrict-&gt

  • , In); // Get The Current Line ( NEW ) shaderData[i][0] = shaderData[i][1] = shaderData[i][2] = float(atof (Line)); // Copy Over The Value ( NEW ) } fclose...); // Set The Color Of The Model ( NEW ) // ORIGINAL DRAWING CODE //Draw the model as an interpolation between the two frames glBegin(GL_TRIANGLES); for(int i = 0; i...I am quite new to OpenGL, I have managed after long trial and error to integrate Nehe's Cel-Shading rendering with my Model loaders, and have them drawn using the Toon shade and outline

  • ; outside that space, white is drawn. Here is my OpenGL init code... SDL_SetVideoMode(windowWidth, windowHeight, 16, SDL_HWSURFACE|SDL_GL_DOUBLEBUFFER|SDL_OPENGL); glClearColor(0, 0, 0, 0); glClearDepth(1.0f); glViewport(0, 0, windowWidth, windowHeight); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, windowWidth, windowHeight, 0, 1, -1); glMatrixMode(GL_MODELVIEW); glEnable(GL_TEXTURE_2D...; glGenTextures(1, &thisIsMyTexture); temporarySurface = loadImage("theimagetomytexture.png"); glBindTexture(GL_TEXTURE_2D,thisIsMyTexture); glTexImage2D(GL_TEXTURE_2D, 0, 4, temporarySurface-&gt;w

  • } // this is the function used to render a single frame void render_frame() { // clear the window to a deep blue and clear the depth buffer to 1.0f device-&gt;ClearRenderTargetView(rtv, D3DXCOLOR(0.0f, 0.2f, 0.4f...() { } Cube::~Cube() { pBuffer-&gt;Release(); // why does this only work when put here? because it's created here? I thnk so, why not iBuffer though? } void Cube::Draw() { render_frame(); } void Cube...Basically when placed in the same file this works fine, but if placed in separate files (and I have tested this) just after Init() is called, the pointer to ID3D10* device's value is suddenly

  • I have got stupid and annoying problem in my app. I am using bullet physics and I've started with hello world example on wiki: http://bulletphysics.org/mediawiki-1.5.8/index.php/Hello_World There is someting like this: btDefaultMotionState* fallMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,50,0))); What is described as set object 50m above something. So I can change the height but nothing more. I can't move it left, right - anything. Also when I set 0 everywhere ( I mean in btVector3) the object is jumping up rather than falling down

  • = xyCoords.y; m_font-&gt;DrawTextA(NULL, stateStream.str().c_str(), -1, &rct, DT_LEFT|DT_NOCLIP , D3DXCOLOR(1,0,0,1)); This all works perfectly. Where am I going wrong with the first bit of code...) * 2.0f - 1.0f, (xyCoords.y / SCREEN_HEIGHT) * 2.0f - 1.0f); lineRenderer.Draw2DLine(origin, headPos, D3DXCOLOR(1, 0, 0, 1), D3DXCOLOR(1, 1, 0, 1)); origin has a value of -1, -1 which is fine... = D3DXVECTOR2( (xyCoords.x / 1280.0f) * 2.0f - 1.0f, (xyCoords.y / 720.0f) * 2.0f - 1.0f); for origin I get (-1, 1.2) and for headPos I get (0, 1.401e-043#DEN). FYI HeadPosition

Data information