applyImpulse help?

jayman
Posts: 1
Joined: Sun Oct 05, 2008 5:16 am

applyImpulse help?

Post by jayman »

what is the impulse vector relative to(World space or objectSpace)? applyImpulse(impulse, relpos)

relpos is relative to the rigidbody, but what about impulse force vector, relative to object right?

I've used physx and many other physics engines and have not seen this strange behaviour, I have a test a cube size (1,1,1), sitting on a plane at world position (0,0.5,0) ,now if i do

Code: Select all

impulse = (0,1,0); // UpVector of Box
relPos   =  (0,0,-0.5); //Back of Box
applyImpulse(impulse,relPos); 
This works ok, but if I keep on applying this impulse and cause the box to align say in a different orientation, it no longer acts Relative to the Box!?? It acts as if relPos(0,0,-0.5) is relative to the world, what could be going wrong here?

Cheers.
rusty
Posts: 25
Joined: Fri Sep 19, 2008 10:23 am

Re: applyImpulse help?

Post by rusty »

As far as I'm aware, the impulse vector is in world space. The position at which the impulse is applied, is relative to the body position.
mreuvers
Posts: 69
Joined: Sat May 10, 2008 8:39 am

Re: applyImpulse help?

Post by mreuvers »

That seems to be correct when looking at the sourcecode (btRigidBody.h)

Code: Select all

	void applyCentralImpulse(const btVector3& impulse)
	{
		m_linearVelocity += impulse * m_inverseMass;
	}
	
  	void applyTorqueImpulse(const btVector3& torque)
	{
			m_angularVelocity += m_invInertiaTensorWorld * torque;
	}
	
	void applyImpulse(const btVector3& impulse, const btVector3& rel_pos) 
	{
		if (m_inverseMass != btScalar(0.))
		{
			applyCentralImpulse(impulse);
			if (m_angularFactor)
			{
				applyTorqueImpulse(rel_pos.cross(impulse)*m_angularFactor);
			}
		}
	}
Based on this code, I guess it should be possible to write an alternative version that applies the impulse relative to the object.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: applyImpulse help?

Post by Erwin Coumans »

The applied impulse vector is in world space, but the location is in local space.

Agreed, it would be better to have a world space version and object space version for both. We will fix this in Bullet 3.x.

Thanks for the feedback,
Erwin
CodeWarrior
Posts: 3
Joined: Fri Dec 11, 2009 10:00 am

Re: applyImpulse help?

Post by CodeWarrior »

rel_pos is actually distance-from-center-of-mass (thus it's in world space too):

btVector3 relPos = hitPoint_in_world_space-rgBody.getCentreOfMassPosition();
rgBody.applyImpulse(impulse,relPos);

What i found confusing was this "Local space" term as i understand the local space is the one rotated with body having <0,0,0>in its center of mass. Consider a 2m tall drunk who got out of pub door at <0,0,0> exiting towards +z, stumbled over the treshold, fell, and now he lies face down. His local space face position <0,1,0> (one meter above his belly) is equal to world space <0,0,2> (two meter out of door). :wink: