Jump to content
  • Advertisement
Sign in to follow this  

Bullet BoxShape landing...oddly

This topic is 1140 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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!