I would like to create a perfectly sticky horizontal floor, so that an object touching it would not be allowed to translate or rotate around the vertical axis. I'm having difficulties with the implementation though.
I'm using the contact added, processed and destroyed callbacks to route contact events directly to rigid bodies like so:
Code: Select all
bool customContactAddedCallback(btManifoldPoint& cp, const btCollisionObjectWrapper* colObj0Wrap, int partId0, int index0, const btCollisionObjectWrapper* colObj1Wrap, int partId1, int index1)
{
RigidBody* obj1 = reinterpret_cast<RigidBody*> (colObj0Wrap->getCollisionObject()->getUserPointer());
RigidBody* obj2 = reinterpret_cast<RigidBody*> (colObj1Wrap->getCollisionObject()->getUserPointer());
if (obj1 == 0 or obj2 == 0)
return false;
return (obj1->collide(obj2) or obj2->collide(obj1));
}
bool customContactProcessedCallback(btManifoldPoint& cp, void* body0, void* body1)
{
RigidBody* obj1 = reinterpret_cast<RigidBody*> (static_cast<btCollisionObject*> (body0)->getUserPointer());
RigidBody* obj2 = reinterpret_cast<RigidBody*> (static_cast<btCollisionObject*> (body1)->getUserPointer());
if (obj1 == 0 or obj2 == 0)
return false;
return (obj1->collide(obj2) or obj2->collide(obj1));
}
bool customContactDestroyedCallback(void* ptr)
{
return false;
}
extern ContactAddedCallback gContactAddedCallback;
extern ContactProcessedCallback gContactProcessedCallback;
extern ContactDestroyedCallback gContactDestroyedCallback;
BulletSimulation::BulletSimulation()
{
gContactAddedCallback = customContactAddedCallback;
gContactProcessedCallback = customContactProcessedCallback;
gContactDestroyedCallback = customContactDestroyedCallback;
}
Now inside the collide() method of my RigidBody class I tried several things.
1. Using setLinearFactor() and setAngularFactor() to set a factor of 0 on all the right axes. This seems to do the trick, but it's also a permanent modification. And since I'm unable to route the contact destroyed callback to specific rigid bodies, I screw up the physics of my RigidBodies for good.
2. Using setLinearVelocity() and setAngularVelocity() on the right axes to set a velocity of 0. No noticable effect.
3. Setting m_combinedFriction to a high value (1000). This is a property of the contact points that I get passed as an argument (btManifoldPoint) to the callback, so it doesn't fit with my routing to the rigid bodies framework, but at least it does something and increases the friction. It's not perfectly sticky though and I would like to have more.
Can anyone please help me with achieving what I want and make suggestion of what I'm doing right or wrong?