[SOLVED] ApplyForce reference frame

Post Reply
RoBaaaT
Posts: 1
Joined: Mon Sep 26, 2016 4:32 pm

[SOLVED] ApplyForce reference frame

Post 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
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: ApplyForce reference frame

Post 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.
StabInTheDark
Posts: 29
Joined: Sat May 18, 2013 1:36 am
Location: NY
Contact:

Re: ApplyForce reference frame

Post 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 );
	}
Post Reply