Collision Handling

syedhs

21-11-2006 06:49:23

Hi,

As per my knowledge, I noticed that ODE does not have a callback which informs the first contact with other geometries. For example, Wood Log upon touching the ground will produce repetitive collision callback (as long as it touches the ground) which makes it difficult to implement like sound collision.

Question 1:
Has such thing is built-in within ODE? One single notification upon geometry touching the other.

Question 2: (Not really a question :wink: )
I have implemented my own collision notification which sounds good for me. 10 geometries colliding with each other produce satisfactory sound. So if there is anyone interested, I will be willing to share it thru WIKI after some code cleanup. However if answer to Question (1) is yes, then my effort is obviously duplicated and my code would probably not be useful to to others. :wink:

Edit: Where is tuan..?

tuan kuranes

29-11-2006 14:51:26

1: no. sounds a good idea for a patch.
2: That could even be a patch. ;)

Edit: Where is tuan..?
Back ;)

syedhs

29-11-2006 17:47:56

Yay.. tuan is back :)

Okay I will submit the code after some cleanup.. but I would like to know whether this algorithm sounds good enough or can be bettered.

Maybe an example will do the explanation easier - lets suppose a log hit a terrain. Currently, the collision callback is called many many times as long as log touches the ground (the same thing too when log is already on ground). The following (simplified) log will illustrate my point:

00:00:01 Log touches ground!
00:00:01 Log touches ground!
00:00:01 Log touches ground!
00:00:01 Log touches ground!
00:00:01 Log touches ground!
00:00:01 Log touches ground!
00:00:01 Log touches ground!
...


So my algo is to wait for a very brief period (50ms) and when the log still touches the ground, declare it as indeed the first collision and do the whatever notification eg producing sound! Similarly.. the collision is assumed to stop (such as log being thrown in the air) when the no such collision occurs after a very brief period (50ms).

And also, I have to mark which geometry is a terrain as terrain touches with a lot of other geometries - so special handling is needed.

Maybe I worry too much - I think I will just post the code quite soon
:wink:

tuan kuranes

29-11-2006 19:59:07

I don't get the 50 ms latency needs. If something collides, why should it collides 50ms to let user knows it collides ?


My idea of the thing was like :

2 sorted std::list or std::queue Frame_collisions and Previous_Frame_Collision at each frame, where insertion Frame_collisions in only can happen once by geometry pair colliding.

At end of frame :

New collisions that will lead to a user callback call "Start Collision Event", are those not existing in Previous_Frame_Collision but in Frame_collisions.
Collision finished that will lead to a user callback call "End Collision Event", are those existing in Previous_Frame_Collision but not in Frame_collisions.
Then Frame_collisions become Previous_Frame_Collision which is cleared.

nikki

30-11-2006 07:13:39

I do it like this:-

1. When the object is created, set a variable mTime to 0;
2. When it collides:-
if (mTime == 0)
//do stuff

mTime = (mTime > 15) ? 0 : (mTime + 1);


This way, you 'do the stuff' only every 15 collision frames. :P

tuan kuranes

30-11-2006 08:54:37

how do you handle multiple collision on a single geometry ?

syedhs

30-11-2006 16:13:21

1. My class can handle collision with multiple geometry. It was a problem at the early stage, but the class can now handle it.

2. The reason why there is a 50 ms is because ODE collision callback sometimes will result like this:-


Vehicle hits house
Vehicle hits house
Vehicle hits house
Vehicle hits house
Vehicle hits NULL
Vehicle hits house
Vehicle hits house

even though the vehicle has actually kept colliding with house. So the 50ms latency provides the nice workaround.