misterface
21-04-2006 22:08:00
The situation:
one mesh, one coll object, ...!!
and a car with 4 wheels and a body (can drive in each direction, so there is no front or back)
gravity is set
All this code works, collision works, gravity works,....
The problem:
int collisionCounter=0;
The car rides on the floor, IF the car hits the wall I want collisionCounter++
How can I do this in my situation?
walaber
22-04-2006 08:13:02
you can use the faceID when creating the TreeCollision background object. then inside the contactCallback (userProcess function), you can check which faceID is causing the collision. if it is the wall, you can increment your counter.
misterface
22-04-2006 10:53:22
great!
But everything is one mesh. (wall+floor+doors=mylevel.mesh)
bool optimalisatieTreeCollision = false;
Entity* level1Entity = mSceneMgr->createEntity("Level1", "level1.mesh");
SceneNode* level1SceneNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("Level1");
level1SceneNode->attachObject(level1Entity)
OgreNewt::Collision* level1Col = new OgreNewt::CollisionPrimitives::TreeCollision(m_World, level1SceneNode, optimalisatieTreeCollision);
level1Col->setUserID(???);
OgreNewt::Body* level1Body = new OgreNewt::Body( m_World, level1Col );
delete level1Col;
level1Body->attachToNode( level1SceneNode );
So I will need multiple userIDs in one TreeCol
walaber
22-04-2006 23:17:38
no, not the "userID", but the "faceID". OgreNewt sets the "faceID" for each face in the collision to the index of the submesh in the mesh. So, the faceID in the treecollision is different for each material assigned to the mesh's faces.
the way you get the ID is to get the submesh index for the submesh using the material you want. so for example, if you have a big level with some "ice" areas, you probably have an "ice" material assigned to those faces. if you know that submesh #3 of your big mesh are the faces with that material, the faceID (that you get in contactProcess()) will also be "3".
misterface
24-04-2006 00:18:51
thx walaber for the help. looks like what I need!
But I'm still having problems with collisionCallbacks
difficult for me to create those callbacks.
I'll give it another shot tomorrow
misterface
29-04-2006 02:45:40
you can use the faceID when creating the TreeCollision background object. then inside the contactCallback (userProcess function), you can check which faceID is causing the collision. if it is the wall, you can increment your counter.
Can you give me more info on how to use the faceID?
I can only give 1 materialID to the treecol object instead of several for each material.
Entity* level1Entity = mSceneMgr->createEntity("Level1", "level1.mesh");
SceneNode* level1SceneNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("Level1");
level1SceneNode->attachObject(level1Entity);
OgreNewt::Collision* level1Col = new OgreNewt::CollisionPrimitives::TreeCollision(m_World, level1SceneNode, optimalisatieTreeCollision);
OgreNewt::Body* level1Body = new OgreNewt::Body(m_World, level1Col);
delete level1Col;
level1Body->attachToNode(level1SceneNode);
level1Body->setMaterialGroupID(matIDLevel);
the callback (with unfortunately always the same id for the m_body1)
void BotsingCallback::userProcess()
{
int id0 = m_body0->getMaterialGroupID()->getID();
int id1 = m_body1->getMaterialGroupID()->getID();
...
OvermindDL1
29-04-2006 02:52:47
In newton, each point can have it's own ID, good for different terrains and such, snow, dirt, etc...
Unsure how to add those in OgreNewt however...
misterface
30-04-2006 16:00:03
level1Entity->getSubEntity(6)->setMaterialName("plinten");
this is close to what I need, is there not some kind of method level1Entity->getSubEntity(6)->setMaterialGroupID(..) (THIS DOES NOT EXIST

)
walaber
30-04-2006 18:55:25
the TreeCollision creator in OgreNewt assigns an ID == to the submech number.
so inside your callback, when you check the "faceID" of the collision, if it is on a face from mesh->getSubMesh(0), the returned value will be 0.
if it is from mesh->getSubMesh(5), the returned value will be 5.
misterface
30-04-2006 21:18:32
the TreeCollision creator in OgreNewt assigns an ID == to the submech number.
so inside your callback, when you check the "faceID" of the collision, if it is on a face from mesh->getSubMesh(0), the returned value will be 0.
if it is from mesh->getSubMesh(5), the returned value will be 5.
I understand!
But my callback gives me always the same id! not the id of the submesh
Entity* level1Entity = mSceneMgr->createEntity("Level1", "level1.mesh");
SceneNode* level1SceneNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("Level1");
level1SceneNode->attachObject(level1Entity);
OgreNewt::Collision* level1Col = new OgreNewt::CollisionPrimitives::TreeCollision(m_World, level1SceneNode, optimalisatieTreeCollision);
OgreNewt::Body* level1Body = new OgreNewt::Body(m_World, level1Col);
delete level1Col;
level1Body->attachToNode(level1SceneNode);
//voor wrijving & botsingen
matIDLevel = new OgreNewt::MaterialID( m_World );
level1Body->setMaterialGroupID(matIDLevel); // !!!!!!!!!!!!!!!!!!!
matPairLevelRolstoelBody = new OgreNewt::MaterialPair( m_World, matIDobject, matIDLevel ); // !!!!!!!!!!!!!!
// callback
botsingCallback = new BotsingCallback();
matPairLevelRolstoelBody->setContactCallback( botsingCallback );
walaber
30-04-2006 23:55:45
in your callback, you need to use getContactFaceAttribute() to get the ID of the face currently colliding.
misterface
01-05-2006 00:17:52