callback for btRigidBody activation state change ?

nigul
Posts: 12
Joined: Tue Sep 22, 2009 1:40 pm

callback for btRigidBody activation state change ?

Post by nigul »

hello,

I have an application with several btDynamicsWorld . Each of these worlds has to know whether it needs an update with stepSimulation(). for the moment, I just step through the btCollisionObjectArray of the btDynamicsWorld and ask each object for its current activation state. If there is no active object, then the world doesn't have to ask for refresh.
This works quite well, but I wonder if this solution is efficient. Is there a possibilty to add a callback to a btRigidBody when its activation state changes from 'active' to 'inactive' ?

thanx
tp
Posts: 13
Joined: Sat Dec 09, 2006 8:10 am

Re: callback for btRigidBody activation state change ?

Post by tp »

I find myself looking for an activation/deactivation callback as well. Is there a reason there isn't one available?

Is there a reason why something like the following would cause problems? (A callback object etc. would be more sophisticated, but I want to keep the lines to a minimum if I have to keep hacking this into the distribution.)

Code: Select all

void btCollisionObject::setActivationState(int newState) 
{ 
	if ( (m_activationState1 != DISABLE_DEACTIVATION) && (m_activationState1 != DISABLE_SIMULATION))
	{
		int oldState = m_activationState1;
		m_activationState1 = newState;
		if (m_activationCallback)
		{
			if ((oldState == ISLAND_SLEEPING || oldState == WANTS_DEACTIVATION) && newState == ACTIVE_TAG)
				m_activationCallback(this, true);
			else if (newState == ISLAND_SLEEPING && (oldState == WANTS_DEACTIVATION || oldState == ACTIVE_TAG))
				m_activationCallback(this, false);
		}
	}
}
sparkprime
Posts: 508
Joined: Fri May 30, 2008 2:51 am
Location: Ossining, New York

Re: callback for btRigidBody activation state change ?

Post by sparkprime »

Depends what you do in the callback. If you call back into bullet, you might catch it with its pants down.
tp
Posts: 13
Joined: Sat Dec 09, 2006 8:10 am

Re: callback for btRigidBody activation state change ?

Post by tp »

Yes good point, thanks.

Maybe someone who knows might comment if there's a better way to do this.