Extending rigid body/collision object interface?

User avatar
SynapticBytes
Posts: 74
Joined: Thu Feb 10, 2011 8:27 pm

Extending rigid body/collision object interface?

Post by SynapticBytes »

In creating my plugin for Shiva3D, I need to pass a string reference to a Shiva object back and forth to my bullet plugin, and link the shiva model to the rigid body via this string.

So far, I've got away with a map structure, using the string as the key to find the corresponding rigid body pointer. However, now that I am trying to implement collision responses, I need to be able to lookup the string from the given collision obj based on this example code snippet from the wiki

Code: Select all

	for (int i=0;i<numManifolds;i++)
	{
		btPersistentManifold* contactManifold =  physicsWorlds[currentWorldID]->getDispatcher()->getManifoldByIndexInternal(i);
		btCollisionObject* obA = const_cast<btCollisionObject*>(contactManifold->getBody0());
		btCollisionObject* obB = const_cast<btCollisionObject*>(contactManifold->getBody1());
When obA & obB are returned, I need to send a callback event back up to the shiva code, using my string which identifies in Shiva what these collision objects are attached to. Now, I could just do a linear search through my map structure to find the matching object pointer, but that will be very inefficient, especially in code running every physics tick substep.

Ideally, I should probably override the btRigidBody (similar to what I have done for the motion state setup) to add my string as a member variable on creation, but my C++ experience is still new, so I'm not sure whether this is easily possible if at all), and what problems it might occur both with the current bullet code, and for upgrading to future versions.

Can anyone suggest the best way to achieve what I need?

Thanks.
User avatar
SynapticBytes
Posts: 74
Joined: Thu Feb 10, 2011 8:27 pm

Re: Extending rigid body/collision object interface?

Post by SynapticBytes »

Well, I managed to upcast my body's motion state to my custom motion state, and used the string stored there. Not sure if this is best practice, but it works, but I'd still be interested to know whether it's advisable to try and extend the bullet classes by inheritance?
rtrius
Posts: 43
Joined: Sat May 26, 2012 1:09 am

Re: Extending rigid body/collision object interface?

Post by rtrius »

It is best to avoid extending the classes unless necessary(such as adding a callback or collision shape).

You can use btCollisionObject::setUserPointer() / getUserPointer() to associate information with the rigid bodies.
User avatar
SynapticBytes
Posts: 74
Joined: Thu Feb 10, 2011 8:27 pm

Re: Extending rigid body/collision object interface?

Post by SynapticBytes »

rtrius wrote:It is best to avoid extending the classes unless necessary(such as adding a callback or collision shape).

You can use btCollisionObject::setUserPointer() / getUserPointer() to associate information with the rigid bodies.
Ahh cool. I missed that method. Thanks very much.