Per-object contact callback?

runevision

05-06-2006 14:06:35

When making a game with quite a bit of different object, each with different actions to be performed upon collision, how is it handled most effectively?

MaterialPairs are clever for some things, but with many different objects that need unique actions (say, n objects) the amount of pairs needed will be n*(n-1)/2 which can be really a lot.

I'd like to have just a few types of materials (and thus, just a few types of material pairs), and then be able to call some additional specific actions on certain combinations of objects regardless of their materials. Like eg. "this object have the environment material and acts like the environment when any object collide with it, but besides that, it triggers this specific action when the player collides with it". How would I do something like that?

Thanks in advance,
Rune

abecam

05-06-2006 16:17:20

You can define a material pair with its callback, and in the callback you check the Object ID (or some user data you have defined), do something if you recognize it, and nothing else... So you don't need so much material pairs, just one to have the callback.
Should work... ? :wink:

runevision

05-06-2006 16:41:16

You can define a material pair with its callback, and in the callback you check the Object ID (or some user data you have defined), do something if you recognize it, and nothing else... So you don't need so much material pairs, just one to have the callback.
Should work... ? :wink:


Yeah, but that means that the code have to do n checks every time something collides if there are n of these special objects. That seems very inefficient. I don't understand why the concept of attaching a ContactCallback to a material can't be extended to allow to also attach a ContactCallback to specific bodies. Preferably allowing attaching an arbitrary number of CollisionCallbacks to a body, using a simple listener design pattern. This would seem obvious? I had hoped something like that was already possible in some way I hadn't figured out yet.

Rune

abecam

05-06-2006 17:04:42

Then for that I really don't know :oops: ... I don't know Newton enough (this is Newton's choice I think, not OgreNewt) :? . Then you can have a mixed solution: define some materials, not too much, and do some "dispatching" in the callbacks as needed... That's not your solution obviously, but it's a way to optimize it :roll: .
But I am interested also if someone has a solution as you describe.

walaber

05-06-2006 17:32:47

unfortunately this is not the way Newton is designed. Newton is designed where you have a small number of materials, and you use the powerful filtering of the callbacks to do more complex things.