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
[SOLVED] ApplyForce reference frame
-
- Posts: 849
- Joined: Tue Sep 30, 2014 6:03 pm
- Location: San Francisco
Re: ApplyForce reference frame
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.
-
- Posts: 29
- Joined: Sat May 18, 2013 1:36 am
- Location: NY
Re: ApplyForce reference frame
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 );
}