Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have got some problem in my OpenGL game. I am using bullet physics and I want to achive quite simple effect - I want one object (a sphere) to roll and hit another (box) which will fall down.

I have got almost everything but still I have got some errors. When the box is hit it is rotating almost how I would like to. Well, almost means that when ball hits it it falls and rotates however there are about 20 degrees left to the ground.

It isn't stoping on a ball because the speed is so high that it is throw away and after a while it "meets" ball

This is my code for objects (including floor) initialization:


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

    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(0,groundMotionState,groundShape,btVector3(0,0,0));
btRigidBody* groundRigidBody = new btRigidBody(groundRigidBodyCI);

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


    pinShape = new btBoxShape(btVector3(0.5,2,0.5));

    btDefaultMotionState* fallMotionState2 = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,3,0)));
    btScalar mass2 = 1;
btVector3 fallInertia2(0,0,0);
    btRigidBody::btRigidBodyConstructionInfo fallRigidBodyCI2(mass2,fallMotionState2,pinShape,fallInertia2);
pinRigidBody = new btRigidBody(fallRigidBodyCI2);

and this is how I am setting the box position and rotation:

btTransform trans2;
    cubeX = trans2.getOrigin().getX();
    cubeY = trans2.getOrigin().getY();
    cubeZ = trans2.getOrigin().getZ();

    rot = trans2.getRotation();


Can someone tell me what is wrong in it? I have got no idea what else I can do.

share|improve this question
Screenshots would help. – Tetrad Jan 7 '12 at 19:10
up vote 3 down vote accepted

There is an error in the code where the rotation of the box is passed to OpenGL.

btTransform::getRotation does not return an euler angle (like used in the code with glRotatef) but a quaternion.

Instead of btTransform::getOrigin and btTransform::getRotation use btTransform::getOpenGLMatrix and pass that matrix to OpenGL using glMultMatrixf.

Here is the corrected code, assuming bullet is used with single precision floating points, so btScalar is a float

    // get the transformation of the body into an OpenGL matrix
    btTransform trans2;
    btScalar m[16];

    // pass that matrix to OpenGL and render the cube
share|improve this answer
Thank you very, very much for your help and advice. Now it works just great. – sebap123 Jan 8 '12 at 13:04
@sebap123 you're very welcome. I noticed you use different values for the box height in glScalef it is 5.0, but in pinShape it is 2.0. You might want to use the same values for the correct visual results. Anyway, good luck for your game :) – Maik Semder Jan 8 '12 at 13:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.