Geometry setUserAny and collisions

relloe

21-11-2010 19:08:40

Hi,

I'm new here and I have been playing around with OgreOde for some time now and got some simple game running on it really easily.

Now I'm trying to modify the default prefab vehicle to get information if the car hull collided with other objects.
By default the prefab vehicle loader generates AABB box for the collision and attaches it to the geometry of the vehicle.

I added the following to the end of OgreOdeLoader.cpp::parseVehicle to set name for the body and bind vehicle object to user data:
vehicle->getGeometry()->setName("Vehicle Body");
vehicle->getGeometry()->setUserAny(Ogre::Any(vehicle));

And in collision callback from the world I print to log the following:

Geometry *geom = contact->getFirstGeometry();
Ogre::Any a = geom->getUserAny();
Geometry *geom2 = contact->getSecondGeometry();
Ogre::Any b = geom2->getUserAny();

if(!a.isEmpty())
{
LogManager::getSingleton().logMessage(LML_NORMAL, geom->getName());
}

if(!b.isEmpty())
{
LogManager::getSingleton().logMessage(LML_NORMAL, geom2->getName());
}

And I don't never see Vehicle Body in the logs nor get the get the vehicle as userAny when checking in debugger.

I got this to work when I ignored the first frame of collision data, and set the geom and geom2 userAny variables manually (post collision geom->setUserAny(Ogre::Any(vehicle)), but this is not what I'd like to do in long run..

Do you have idea why the data gets lost from the userAny and name fields..?
Or alternatively is there some other good way to write custom collision response hooks..?