How do you manage collisions logic in ODE?

Started by
1 comment, last by riruilo 14 years, 2 months ago
Hi mates! I'm using ODE for first time, and I have some questions about contacts. Can you help me? What I don't understand is how to manage these contacts with my NPC state charts. I mean, let's say I want to play a contact sound, or I want to add an impulse everry time my NPC or rigid body touches floor (usually I do these things using a FSM, finite state machine). The question is, should I send these contact points to my entities (that contain a body and a geom each one)? Should I add something just before dJointGroupEmpty(m_contact_group); in order to save these contact points in my own entities?

void CScene::UpdatePhysics(int delta) {
	dSpaceCollide (m_space_id,this,&CScene::nearCallback);
	dWorldStep(m_world_id, FRAME_TIME*0.001);
	dJointGroupEmpty(m_contact_group);
}
Thanks a lot for your help and time.
I've seen things you people wouldn't believe. Attack ships on fire off the shoulder of Orion. I watched C-beams glitter in the dark near the Tannhauser gate. All those moments will be lost in time, like tears in rain. Time to die.
Advertisement
One way to handle collision events for a particular geom is to give it a unique category (set a unique category bit) when you create it. During creation, if you need information about the geom or body, set a pointer to the class instance or to some data struture with dGeomSetData(geomID,(void*)pointerToSomething). In my constructor, I use dGeomSetData(geomID,(void*)this) so I can access anything in the instance.

Then, in the collision callback (ODE_NPC is whatever category bit you have for your class):
if( (dGeomGetCategoryBits(o1) & ODE_NPC) | (dGeomGetCategoryBits(o2) & ODE_NPC) ){   // however you want to handle the collision   // remember, both geoms may be ODE_NPCs if they can collide with each other   dGeomID npcID = dGeomGetCategoryBits(o1) & ODE_NPC ? o1 : o2;   ... do your stuff   YourClassOrStructure *ptr = dGeomGetData(npcID);   ... do something with ptr->dataYouNeed   if( you want to do the collision yourself )   {      .. do your stuff      return;   }}// continue with collision detectionn = dCollide(...);

Note: there is a google users group for ODE that is quite active.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Quote:Original post by Buckeye
One way to handle collision events for a particular geom is to give it a unique category (set a unique category bit) when you create it. During creation, if you need information about the geom or body, set a pointer to the class instance or to some data struture with dGeomSetData(geomID,(void*)pointerToSomething). In my constructor, I use dGeomSetData(geomID,(void*)this) so I can access anything in the instance.

Then, in the collision callback (ODE_NPC is whatever category bit you have for your class):
if( (dGeomGetCategoryBits(o1) & ODE_NPC) | (dGeomGetCategoryBits(o2) & ODE_NPC) ){   // however you want to handle the collision   // remember, both geoms may be ODE_NPCs if they can collide with each other   dGeomID npcID = dGeomGetCategoryBits(o1) & ODE_NPC ? o1 : o2;   ... do your stuff   YourClassOrStructure *ptr = dGeomGetData(npcID);   ... do something with ptr->dataYouNeed   if( you want to do the collision yourself )   {      .. do your stuff      return;   }}// continue with collision detectionn = dCollide(...);

Note: there is a google users group for ODE that is quite active.


OK, thanks a lot, I will try it out ;)
I've seen things you people wouldn't believe. Attack ships on fire off the shoulder of Orion. I watched C-beams glitter in the dark near the Tannhauser gate. All those moments will be lost in time, like tears in rain. Time to die.

This topic is closed to new replies.

Advertisement