Collision Callback system NEEDS an overhaul

Wavesonics
Posts: 71
Joined: Thu May 22, 2008 8:03 pm

Collision Callback system NEEDS an overhaul

Post by Wavesonics »

Like the title says, the Collision Callback system absolutely, positively, needs an over haul.

Very simply, it doesn't work well enough to be used by a production game right now.

Here is what I propose:
Each callback should get 2 pointers, one to each btCollisionBody that is part of the collision. From there the user can get their user pointers and do what they want.

Then there is no issue with m_userPersistenceData or what ever else is currently the method for doing this.

Probably:

Code: Select all

void CollisionAdded( btCollisionBody col0, btCollisionBody col1 );
void CollisionDestroyed( btCollisionBody col0, btCollisionBody col1 );
would be the callbacks.

The current system is designed to allow the user to do things inside the physics engine pretty much exclusively (the problems with propagating user data makes game logic difficult if not impossible). But providing these new callbacks I'm talking about would be more geared towards allowing game logic to be executed with the proper information it needs.

Passing btCollisionBody to these functions is better then passing the user data pointer because it provides the link between the user data and the physical object, which allows the callback code to only execute game logic using the user data, or to also if it so chooses, do things inside the physics engine via the btCollisionBody.

Also a nicer way of registering the callbacks, maybe even a function pointer in each btCollisionObject to their individual callback which can be set using a proper function.
No more globals :/

What do you guys think? If the devs like this idea and could give me some idea of how much time this would take, I would be more then willing to write this and offer it as a patch to the SVN if the devs will actually include it. I desperately need this functionality for my project anyway.
AlexSilverman
Posts: 141
Joined: Mon Jul 02, 2007 5:12 pm

Re: Collision Callback system NEEDS an overhaul

Post by AlexSilverman »

Wavesonics,

I may be mistaken, but doesn't this functionality exist already, and then some? Bullet exposes ContactAddedCallback, ContactProcessedCallback, and ContactDestroyedCallback. I only use the first so I cannot speak to the other two, but it seems to offer exactly what you mention.

The signature is

Code: Select all

typedef bool (*ContactAddedCallback)(btManifoldPoint& cp,	const btCollisionObject* colObj0,int partId0,int index0,const btCollisionObject* colObj1,int partId1,int index1);
This gives you the ability to not only alter each object but also the general properties of the specific collision (friction, restitution, collision normal, etc). I see this ContactAddedCallback function as being one of the points where the physics engine code touches game code.

I have used Bullet in 2 professional projects thus far, and the current system works as follows. I created a physics subsystem for the engine, which contains a definition for a ContactAddedCallback function. Each game object that has a physical representation uses the btCollisionObject::m_userObjectPointer to point back to the game object that the btCollisionObject is representing, sort of like an owner pointer of sorts. This allows me to execute game logic from within the ContactAddedCallback. If that's not enough for those writing game code, I also allow each object to register a callback method to be called when that object collides with something, so those also get executed in the ContactAddedCallback as well.

This all adds up to an implementation with lots of room for game code to exist and be initiated by Bullet, while not really intruding upon it. You can find an example of the ContactAddedCallback in the ConcavePhysicsDemo. I'm not sure about demos of the other two types of callbacks, but I'm sure the implementation can be found with a simple search of the source. That said, what would you like for the callback system to do (or allow you to do) that it doesn't do already?

- Alex
Wavesonics
Posts: 71
Joined: Thu May 22, 2008 8:03 pm

Re: Collision Callback system NEEDS an overhaul

Post by Wavesonics »

Yes I have the AddedCallback working as well, but I am more interested in the destroyed callback which I have yet to get working the way it is suppose to.

After much fussing, I finally have the destroy call back firing, but it is not receiving the user pointer I assigned.

Can you shed any light on this?
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Collision Callback system NEEDS an overhaul

Post by Erwin Coumans »

Wavesonics wrote:Yes I have the AddedCallback working as well, but I am more interested in the destroyed callback which I have yet to get working the way it is suppose to.

After much fussing, I finally have the destroy call back firing, but it is not receiving the user pointer I assigned.

Can you shed any light on this?
Userdate should automatically propagate through the ContactAddedCallback, ContactProcessedCallback, and ContactDestroyedCallback callbacks.

Can you reproduce the issue in a Bullet demo?
Thanks,
Erwin
Wavesonics
Posts: 71
Joined: Thu May 22, 2008 8:03 pm

Re: Collision Callback system NEEDS an overhaul

Post by Wavesonics »

I can't run most of the bullet demos on our system. We have ported Bullet to the Wii and are using it on there. The porting touched a minimal number of files so I very seriously doubt it is an issue with the porting.

But to get this straight, the user pointer coming through in the destroyed contact callback should be the user pointer I set?

I have done pointer comparisons and it is definitely not what I set it to. I will be back on Monday and will look into this and post it as an issue if I can't find any cause.

Can anyone else either confirm or deny that the destroyed callback works for them?
shogun
Posts: 34
Joined: Tue Mar 04, 2008 3:16 pm

Re: Collision Callback system NEEDS an overhaul

Post by shogun »

Wavesonics wrote:Can anyone else either confirm or deny that the destroyed callback works for them?
I have the same problem like you, the user pointer isn't the one i assigned in ContactAddedCallback.
Moreover, I have the strange problem that in ContactAddedCallback, m_appliedImpulse of btManifoldPoint* is always 0.0f.
AlexSilverman
Posts: 141
Joined: Mon Jul 02, 2007 5:12 pm

Re: Collision Callback system NEEDS an overhaul

Post by AlexSilverman »

To try and reproduce this issue in a Bullet demo means that you should alter one of the existing Bullet demos that comes with the SDK (typically I use the CcdPhysicsDemo project) on your PC platform of choice. Try and set up a scene that is as simple as possible while still displaying the problematic behavior. This way there are two options. If the problem is not displayed in the altered Bullet demo, you can work to isolate the difference between the projects (your Wii project and the Bullet demo you altered). If the problem is displayed in the altered Bullet demo, then you can post the altered file(s) here so that those of us who are so inclined can download it and have a common starting point to work from in trying to solve this issue.

- Alex
Wavesonics
Posts: 71
Joined: Thu May 22, 2008 8:03 pm

Re: Collision Callback system NEEDS an overhaul

Post by Wavesonics »

Ok, I have already put a lot of time into this and need to move on for now, but I will get back to this and try to isolate the problem.