My first post so first of all big thanks to all those involved in the development of this fantastic library. I'm a newbie to physics so i'll try not to make any assumptions below...
I am using Bullet for collision detection and rigid body dynamics in a pool/billiards game demo I am working on. I am seeing some jitter with the pool balls when they are awake in the physics simulation. Please see the attached video link: http://www.youtube.com/watch?v=LgDj2MjVgoA
At 22 - 32 seconds of the video when the player is lining up and taking their second shot the other balls near the cue and the white cue ball are jittering up and down. Its as if the balls start falling due to gravity and then the simulation realizes they are on a shape and corrects their positions back up.
Here is how I have set up Bullet:
- Using btDbvtBroadphase, and btDiscreteDynamicsWorld.
- Every frame I am stepping the simulation like:
Code: Select all
m_dynamicsWorld->stepSimulation(deltaSeconds, 4);
Here is part of my bullet internal tick callback where I look for pairs of objects either colliding or seperating. Its pretty standerd. I introduced a test to ensure objects are physically colliding by ensuring i generate collision events only when the number of manifolds is greater than 0. Before i introduced this the pool balls would report a collision when their aabbs collided.
Code: Select all
BulletPhysics * const bulletPhysics = static_cast<BulletPhysics*>(world->getWorldUserInfo());
CollisionPairs currentTickCollisionPairs;
btDispatcher * const dispatcher = world->getDispatcher();
for(int manifoldIdx = 0, numManifolds = dispatcher->getNumManifolds(); manifoldIdx < numManifolds; ++manifoldIdx)
{
btPersistentManifold const * const manifold = dispatcher->getManifoldByIndexInternal(manifoldIdx);
if(!manifold)
{
SafeGameLogAndPrefix(g_appPtr->GetLoggerPtr(),\
GameLog::ERR,\
std::string("BulletPhysics::BulletInternalTickCallback()"),\
std::string("Failed to get the manifold pointer"));
return;
}
if(manifold->getNumContacts() > 0)
{
btRigidBody const * const body0 = static_cast<btRigidBody const *>(manifold->getBody0());
btRigidBody const * const body1 = static_cast<btRigidBody const *>(manifold->getBody1());
bool const swapped = body0 > body1;
btRigidBody const * const sortedBodyA = (swapped ? body1 : body0);
btRigidBody const * const sortedBodyB = (swapped ? body0 : body1);
CollisionPair const thisPair = std::make_pair(sortedBodyA, sortedBodyB);
currentTickCollisionPairs.insert(thisPair);
if(bulletPhysics->m_previousTickCollisionPairs.find(thisPair) == bulletPhysics->m_previousTickCollisionPairs.end())
{
bulletPhysics->SendCollisionPairAddEvent(manifold, body0, body1);
}
}
}
The balls are sphere shapes. The cue is a cylinder shape.
The cue and the cue ball are part of the same collision group so that the cue only affects the cue ball. The cue is a kinematic object. Previously I was taking a shot by moving the cue into the cue ball but i did not get the desired effects. Now instead I am applying an impulse onto the cue ball to take a shot.
The table and ball have the parameters:
INIT_POOLBALL_PHYSICS_INFORMATION =
{
Restitution = 0.75,
Friction = 0.5,
Density = 1.95,
LinearDamping = 0.45,
AngularDamping = 0.5
};
INIT_POOLTABLE_PHYSICS_INFORMATION =
{
Restitution = 0.5,
Friction = 0.5,
Density = 0.0,
LinearDamping = 0.0,
AngularDamping = 0.0
};
Any ideas on what i could do to correct this jitter issue?
Thanks for reading.