Object rotating error in Bullet Physics with OpenGL

  • Object rotating error in Bullet Physics with OpenGL sebap123

    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.

  • 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

c++ opengl bullet-physics
Related questions and answers
  • I have been playing around with Ogre3d and trying to integrate bullet physics. I have previously somewhat successfully got this functionality working with irrlicht and bullet and I am trying to base this on what I had done there, but modifying it to fit with Ogre. It is working but not correctly and I would like some help to understand what it is I am doing wrong. I have a state system and when... btDefaultMotionState(Transform); btCollisionShape *Shape = new btStaticPlaneShape(btVector3(0,1,0),0); // Add Mass btVector3 LocalInertia; Shape->calculateLocalInertia(0, LocalInertia); // CReate

  • 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...,-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...); 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->addRigidBody(ContiRigid); Edit 1: btScalar Mass = 1; btVector3 FallInertia(0,0,0... = new btRigidBody(StillRigidCI); PhysicsWorld->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->getBulletRigidBody(); btGeneric6DofConstraint* constrict = new btGeneric6DofConstraint(*robot, *zeroBody, btTransform::getIdentity(), btTransform::getIdentity(), false); constrict-&gt

  • 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

  • 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... NEHE'S TUT glBegin (GL_TRIANGLES); // Tell OpenGL What We Want To Draw for(int i = 0; i < numTriangles; i++) { MD2Triangle* triangle..., In); // Get The Current Line ( NEW ) shaderData[i][0] = shaderData[i][1] = shaderData[i][2] = float(atof (Line)); // Copy Over The Value ( NEW ) } fclose

  • have updated my code with a new algorithm that checks where the ball was previously before collision. Corner cases work on that single platform correctly now, but when I have a wall of objects, I keep...I am trying to create a 2D platformer (Mario-type) game and I am some having some issues with handling collisions properly. I am writing this game in C++, using SDL for input, image loading, font loading, etcetera. I am also using OpenGL via the FreeGLUT library in conjunction with SDL to display graphics. My method of collision detection is AABB (Axis-Aligned Bounding Box), which is really all

  • To begin with I am developing a PSP application so I have no clue how to debug a PSP application. That doesn't mean I do not know how debug period. Anyway, when I run the game everything runs fine but when I press the X button on the PSP I see no bullet being drawn or updated on the screen. I know the problem doesn't lie with the pad because I press start and it exits my game so I do not think it is the pad that is causing the problem. Maybe the bullet is being drawn out of the screen already. But I am not sure since I cannot debug maybe somebody can see the flaw in my code. main.cpp class

  • I've just started implementing bullet into my Ogre project. I followed the install instructions here: http://www.ogre3d.org/tikiwiki/OgreBullet+Tutorial+1 And the rest if the tutorial here: http..., but I have no idea how Below is the code I'm using. (part of) Header File OgreBulletDynamics::DynamicsWorld *mWorld; // OgreBullet World OgreBulletCollisions::DebugDrawer *debugDrawer; std... = mSceneMgr-&gt;createCamera("PlayerCam"); mCamera-&gt;setPosition(Vector3(0,0,0)); mCamera-&gt;lookAt(Vector3(0,0,300)); mCamera-&gt;setNearClipDistance(5); mCameraMan = new OgreBites

Data information