Collision Callbacks??

Post Reply
davidc538
Posts: 7
Joined: Mon Nov 08, 2010 2:00 am

Collision Callbacks??

Post by davidc538 »

Hey everyone.

I'm looking for an ideal way to do collision callbacks inside bullet, right now im using the btCollisionWorld::ContactResultCallback interface but its addSingleResult function (which ive listed below) seems to provide far too much information and get called several times per collision. does anyone have an eaier way to do this?

Code: Select all

virtual	btScalar addSingleResult(btManifoldPoint&, const btCollisionObject*,
		int, int, const btCollisionObject*, int, int);
also is there a way to create an object (btSphere most likely) and get a list of physics bodies it contacts without having it apply force to them? this would make simulating explosions very easy

thanks in advance
MaxDZ8
Posts: 149
Joined: Fri Jun 24, 2011 8:53 am

Re: Collision Callbacks??

Post by MaxDZ8 »

It was my understanding Ghost Objects were introduced for this specific reason. Have you looked at them?
Antonz
Posts: 16
Joined: Wed Nov 17, 2010 10:57 am

Re: Collision Callbacks??

Post by Antonz »

Are Ghost objects really useful for implementing things like triggers? They needs to be polled for changes and it will be a lot of overhead. Also I don't like them because it's a separate type of object, it's not static object, not kinematic, not dynamic, but "ghost" object, phew. So I cannot really have triggers for dynamic vs kinematic object collision, for example, if I use ghost objects (if I want kinematic object to move by animation when it gets touched by dynamic object). Overall I think ghost objects is a bad design idea - it should be part of collision object functionality that can be turned on, or added into it optionally (like setting callback function/object).

Answering original question:
For my project I tried various methods for implementing triggers and ended setting up gContactProcessedCallback and gContactDestroyedCallback handlers and btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK for all objects requiring trigger functionality. Inside callbacks I quickly check if I'm interested in this contact by checking flag in pointer to my collision object wrapper (stored for every bullet collision object in user pointer) and decide if I want to further process it:

Code: Select all

bool Physics::Engine::ContactProcessedCallback
	( btManifoldPoint& cp
	, void* body0
	, void* body1 )
{
        Physics::CollisionObject * ourCollObj0 = reinterpret_cast<Physics::CollisionObject*>
		(static_cast<btCollisionObject*>(body0)->getUserPointer());
	Physics::CollisionObject * ourCollObj1 = reinterpret_cast<Physics::CollisionObject*>
		(static_cast<btCollisionObject*>(body1)->getUserPointer());

	if (!ourCollObj0->trigger_ && !ourCollObj1->trigger_)
		return false;	// Not interested in this.

	Physics::Engine* physEngine = ourCollObj0->engine_;
	
	return physEngine->ContactProcessedCallback
		(cp, ourCollObj0, ourCollObj1);
}
Post Reply