ContactCallback Material Names [SOLVED]

micken

03-09-2007 04:51:09

I have an OgreNewt::ContactCallback between a character and the world object. I know that in order to tell what face my character is standing on I need to call getContactFaceAttribute in userProcess. I can hack this to act the right way if i use trial and error to find which materialIDs relate to which materials but I would have to re-do this every time the world is updated by the people developing it. It would be immensely more useful to me if i could get the name of the material on the face that the character is standing on so that people creating the world can use naming conventions to have the character react the right way with the materials they use.

For example. instead of going through and finding the right IDs for a concrete floor, the world developers could just call the material "concrete_road1" and it would play a concrete footstep sound.

Does anyone have suggestions for how to accomplish this?

walaber

03-09-2007 05:45:41

probably the easiest way to do this is when you are creating the collision, store a table of values that match a string (the material name you are currently on) to an int (the ID you are giving to a face).


later, when a collision happens, ask the "material id manager" for the string name, given the specific ID.

in other words, generate a table when you load the level, and reference it later on each collision...

micken

03-09-2007 22:38:10

I knew there had to be another way so I dug as deep as i could and here are the results:

I took a look at what the SubMeshNameMap was containing and found that the index of a submesh was directly correspondant to the ContactFaceAttribute. so here's the code that solved my problem:


int WorldCharContactCallback::userProcess()
{
Ogre::SceneNode *nPtr;
Ogre::Entity *entPtr;
nPtr = static_cast <Ogre::SceneNode *> (m_body1->getOgreNode());
entPtr = (Ogre::Entity*) nPtr->getAttachedObject(0);
Ogre::MeshPtr tmpMesh = entPtr->getMesh();
Ogre::SubMesh *tmpSubMesh = tmpMesh->getSubMesh(getContactFaceAttribute());

_cprintf("standing on: %s\n", tmpSubMesh->getMaterialName().c_str());
return 1;
}


I also learned how to use HashMaps.

walaber

04-09-2007 17:50:19

yeah, i believe I setup treecollision to be default set the submesh id as the face id.