Problems with collisions

IFMaster_2005

27-05-2008 20:17:53

Hello, i have some problems trying to detect collsions.

I check the method in OgreBulletCollisionsWorld, discreteCollide, and bascially i copied the code in my project in order to get all the objects are colliding:
mWorld->stepSimulation(evt.timeSinceLastFrame);

btDispatcher *dispatcher = mWorld->getBulletCollisionWorld()->getDispatcher();
const unsigned int numManifolds = dispatcher->getNumManifolds();

for (unsigned int i = 0; i < numManifolds; i++)
{
btPersistentManifold* contactManifold = dispatcher->getManifoldByIndexInternal(i);

btCollisionObject* obA = static_cast<btCollisionObject*>(contactManifold->getBody0());
btCollisionObject* obB = static_cast<btCollisionObject*>(contactManifold->getBody1());

C_Player *player = (C_Player *) obA->getUserPointer();

if (player != NULL)
player->onCollide();

C_Player *player2 = (C_Player *) obB->getUserPointer();

if (player2 != NULL)
player2->onCollide();
}


I initialize my player rigidBody like this:
const float gDynamicBodyRestitution = 0.6f;
const float gDynamicBodyFriction = 0.6f;
const float gDynamicBodyMass = 1.0f;
Vector3 size = Vector3 (0.5, 0.25, 0.5);
Vector3 axe = Vector3(0.0f, 1.0f, 0.0f);

sceneCubeShape = new CylinderCollisionShape(size, axe);
defaultBody = new RigidBody("PlayerRigidBody", C_OgreResources::getMe()->getDynamicsWorld());
Vector3 pos = playerEntity->getOgreEntity()->getParentSceneNode()->getPosition();
pos.y = 0.25f;

defaultBody->setStaticShape(playerEntity->getOgreEntity()->getParentSceneNode(), sceneCubeShape, gDynamicBodyRestitution, gDynamicBodyFriction, pos);
defaultBody->getBulletRigidBody()->setUserPointer(this);


And I put a method in my player class, onCollide, but it is never called.
However, if i put the shape tp the rigidBody with setShape (without using setStaticShape) the method is called.

But i need the player controlled by the logic, is for this cause i dont want use the setShape method.
Any one can help me with this please, thanks a lot in advance and sorry about my poor english.