Page 1 of 1

[SOLVED] ApplyForce reference frame

Posted: Mon Sep 26, 2016 4:43 pm
by RoBaaaT
Hello everybody,

This might seem like a very basic question but I just can't seem to figure it out by myself.
Should the force passed to the applyForce method of the rigidbody be in the world reference frame or in the rigidbodies reference frame?
I tried figuring it out by testing various different values for the force on a simple rigidbody with a box collider, but I got inconsistent results.

Thanks in advance for your answers,
RoBaaaT

Re: ApplyForce reference frame

Posted: Thu Sep 29, 2016 3:53 pm
by drleviathan
btRigidBody::applyForce(const btVector3& force, const btVector3& rel_pos) expects the force argument to be in the world-frame. The rel_pos argument is relative to the body's position, but is rotated with respect to the world-frame.

Re: ApplyForce reference frame

Posted: Sat Oct 01, 2016 6:30 pm
by StabInTheDark
You can convert a local force vector to a world vector and then pass it to applyForce(const btVector3& force, const btVector3& rel_pos). This is how I do it.

Code: Select all

	btMatrix3x3 bodyRotMat = body->getWorldTransform().getBasis();
	btVector3 worldOffsetCOM = bodyRotMat * localOffSetCom;
	if ( local ){
		btVector3 worldForce = bodyRotMat * forceVec;
		body->applyForce( worldForce, worldOffsetCOM );
	}
	else{
		body->applyForce( forceVec, worldOffsetCOM );
	}