Sign in to follow this  
riruilo

How do you manage collisions logic in ODE?

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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 detection
n = dCollide(...);

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

Share this post


Link to post
Share on other sites
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 detection
n = dCollide(...);

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


OK, thanks a lot, I will try it out ;)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this