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.
How do you manage collisions logic in ODE?
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?
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):
Note: there is a google users group for ODE that is quite active.
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.
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 ;)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement