contact callback never called

XpLoDWilD

10-07-2009 11:56:41

Hi everyone,

I want to do some "transports" in my game (you know, big boats, bus, trains, etc...), and in order to make player moving with the vehicle while he's standing on it, I found that the better solution is using a contactCallback (if you have better/easier solution, tell me).

Here's how I initialize my vehicle object :


OgreNewt::Body* CGamePhysics::addTransportCollider(Ogre::SceneNode* node, GameObject* go)
{
// here's where we make a collision shape for the physics. note that we use the same size as
// above.
OgreNewt::Collision* col = new OgreNewt::CollisionPrimitives::TreeCollision(nt_World, node, true);

// now we make a new rigid body based on this collision shape.
OgreNewt::Body* bod = new OgreNewt::Body( nt_World, col, 50 ); // TRANSPORT_ID = 50

// we`re done with the collision shape, we can delete it now.
delete col;

bod->setUserData(go);

// Create materialPair for no bouncing/elasticity/contactCallback
const OgreNewt::MaterialID *mMatDefault = nt_World->getDefaultMaterialID();
const OgreNewt::MaterialID *mMatConveyor = new OgreNewt::MaterialID( nt_World );

OgreNewt::MaterialPair* mNoBouncingMaterial = new OgreNewt::MaterialPair nt_World, mMatDefault, mMatConveyor );
mNoBouncingMaterial->setDefaultElasticity(0);
mNoBouncingMaterial->setDefaultFriction(0.0, 0.0);
mNoBouncingMaterial->setDefaultSoftness(0.0);
mNoBouncingMaterial->setContinuousCollisionMode(1);
mNoBouncingMaterial->setContactCallback(new transportMatCallback(50));

// something new: moment of inertia for the body. this describes how much the body "resists"
// rotation on each axis. realistic values here make for MUCH more realistic results. luckily
// OgreNewt has some helper functions for calculating these values for many primitive shapes!
Ogre::Vector3 inertia = OgreNewt::MomentOfInertia::CalcBoxSolid( 1, node->getAttachedObject(0)->getBoundingBox().getSize() );
bod->setMassMatrix(1, inertia );
bod->setMaterialGroupID(mMatConveyor);

// attach to the scene node.
bod->attachToNode( node );

// this is a standard callback that simply add a gravitational force (-9.8*mass) to the body.
bod->setStandardForceCallback();
//bod->setCustomForceAndTorqueCallback(localForceCallback);
bod->setAutoFreeze(0);

return bod;
}


This function is called after I initialized my Ogre entity/node. If I showLines, the object appears and everything looks good, but I'm unable to get the userProcess function of my callback running. My callback is okay, because if I call setContactCallback on the Player's material, the userProcess function is called, so there's something wrong with my vehicle.
Also, to update the position of my vehicle, I use setPositionOrientation (because it's managed by a server, so to keep things synchronized, I have to define manually the position). If I use setVelocity, my body don't move (maybe it's due to fact I move Ogre node manually ?).
I can stand on my boat, but when it moves, I just slide on it and then fall.

What's wrong ? (I'm using OgreNewt 1.5)

XpLoDWilD

10-07-2009 22:14:26

Solved, I just misunderstood the way that MaterialPair works (I was pairing with unused Material)