Jump to content
  • Advertisement
Sign in to follow this  
riruilo

How do you manage collisions logic in ODE?

This topic is 3074 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
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 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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!