Code: Select all
_btCollisionConfig = new btDefaultCollisionConfiguration();
_btCollisionDispatch = new btCollisionDispatcher(_btCollisionConfig);
btVector3 worldAabbMin(-100,
-100,
-100);
btVector3 worldAabbMax(100,
100,
100);
_broadphase = new btAxisSweep3(worldAabbMin, worldAabbMax);
// Default constraint solver.
_btSolver = new btSequentialImpulseConstraintSolver();
// World object. I believe this is the main object the application will
// interact with
_btWorld = new btDiscreteDynamicsWorld(_btCollisionDispatch,
_broadphase,
_btSolver,
_btCollisionConfig);
// Sets the gravity for this world: Z is up
_btWorld->setGravity(btVector3(0, -0, -10));
/********* Create and position the table ****************************/
_btTableShape = new btBoxShape(btVector3(btScalar(1.48),
btScalar(2.75),
btScalar(0.5)));
// Position the table in the world
btTransform tableXForm;
tableXForm.setIdentity();
tableXForm.setOrigin(btVector3(0, 10, -0.5));
// Set the mass of the table - zero means it can't move
btScalar tableMass(0.0);
btVector3 tableInertia(0, 0, 0);
_btTableState = new btDefaultMotionState(tableXForm);
btRigidBody::btRigidBodyConstructionInfo tableInfo(tableMass,
_btTableState,
_btTableShape,
tableInertia);
_btTableBody = new btRigidBody(tableInfo);
_btWorld->addRigidBody(_btTableBody);
/************** Create and position the ping pong ball ****************/
// 40mm diameter, 2.7 grams
// Should drop from 30cm and bounce to 23cm, COR 0.88
_btBallShape = new btSphereShape(btScalar(0.02));
btScalar ballMass(2.7);
btVector3 ballInertia(0, 0, 0);
_btBallShape->calculateLocalInertia(ballMass, ballInertia);
// Position the ball in the world
btTransform ballXForm;
ballXForm.setIdentity();
ballXForm.setOrigin(btVector3(0, 10, 2.0));
_btBallState = new btDefaultMotionState(ballXForm);
btRigidBody::btRigidBodyConstructionInfo ballInfo(ballMass,
_btBallState,
_btBallShape,
ballInertia);
_btBallBody = new btRigidBody(ballInfo);
_btWorld->addRigidBody(_btBallBody);
The first odd behavior I'm seeing is that the ball appears to fall below the top of the table (to a height of -0.162844) and then 'bounce' to a height of 0.2. I emphasize bounce because the ball doesn't really bounce because it rises to a height of 0.2 and then settles at that height. It almost looks like it bounces as demonstrated in the demo software but instead of peaking and falling back down it continues to rise to a height of 0.2m. I just feel like I'm missing something here.
The second question I have is with respect to gravity acceleration. The ball definitely accelerates downward in the Z direction but the acceleration seems much slower than expected. I timed dropping a ball from one meter and it was significantly faster than my observed results with Bullet. I suspect that this has to do with how I'm stepping the simulation but my diagnostics indicate a smooth 60hz.
The last question I have is with regards to the coefficient of restitution; none of the demo software seemed to address the 'bounciness' of an object. Any tips on where to start to replicate this behavior?