Sign in to follow this  

Bullet BoxShape landing...oddly

This topic is 837 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey all,


I started working with Bullet today, and for my first little test to try and get my feet wet, I decided to make some cubes and drop them and see what happens. I read through the "Hello World" project on the Bullet Wiki, and I believe I've implemented most of the code correctly, but the cubes often land on edges after bouncing and don't seem to be under the full effects of gravity once they "land". Here's what the end result looks like:





The cube on the right has landed correctly, but all other cubes have landed on edges and refuse to "fall flat", so to speak.


Here's my very simple code:


// Create a broadphase to use
broadphase = new btDbvtBroadphase();

// Create a collision configuration to be used by the collision dispatcher
collisionConfiguration = new btDefaultCollisionConfiguration();
dispatcher = new btCollisionDispatcher(collisionConfiguration);

// Set the collision algorithm to use

// Create a solver
solver = new btSequentialImpulseConstraintSolver();

// Initialize the dynamics world
dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration);

// Set gravity
dynamicsWorld->setGravity(btVector3(0, -9.8, 0));

// Set the plane collision shape
planeShape = new btStaticPlaneShape(btVector3(0, 1, 0), 1);

// Set the crate collision shape
crateShape = new btBoxShape(btVector3(0.375, 0.375, 0.375));

// Create the rigid body associated with the mesh
btDefaultMotionState* planeMotionState = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(0, -1, 0)));
btRigidBody::btRigidBodyConstructionInfo planeRigidBodyCI(0, planeMotionState, physicsManager->getPlaneShape(), btVector3(0, 0, 0));
planeRigidBody = new btRigidBody(planeRigidBodyCI);

// Add the plane rigid body to the dynamics world

btDefaultMotionState* crateMotionState = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(x, 50, z)));
btScalar mass = 1.0f;
btVector3 crateInertia(0, 0, 0);
physicsManager->getCrateShape()->calculateLocalInertia(mass, crateInertia);
btRigidBody::btRigidBodyConstructionInfo crateRigidBodyCI(mass, crateMotionState, physicsManager->getCrateShape(), crateInertia);
crateRigidBodyCI.m_restitution = 0.75f;
crateRigidBodyCI.m_friction = 1.0f;
btRigidBody* crateRigidBody = new btRigidBody(crateRigidBodyCI);



After each simulation step, I update the objects translation and rotation according to the bTransform's origin and rotation (which returns a bQuaternion). I do have one idea as to what may be the problem. When I translate my object in 3D space, I set the rotational matrix using Euler angles instead of quaternions. Would there be any sort of issue grabbing the quaternion rotations and plugging them into Euler rotations (I feel like there would be, but I'm new to this smile.png )? If anyone has any ideas as to what I might be doing wrong, the advice is much appreciated! Thanks!


UPDATE: My lack of knowledge regarding quaternions was my downfall! After changing my 3D rotational transform function to using quaternions, I cast the bQuaternion as a glm::quat and I now have cubes that land "flat". This change to quaternions seems to have affected my lighting system somehow, and I will need to investigate, but all is well with the Bullet issue I was having!


Edited by trentfaris242

Share this post

Link to post
Share on other sites

This topic is 837 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this