c++glm-mathbulletphysicsbullet

Getting Forward Right Up Vector From Transformation Matrix


How can I get a Forward, Right, and Up Vector from a Transformation Matrix?

I want to use these vectors as a basis to apply force to rigid bodies in different directions.

btTransform Trans = _RigidBody->getWorldTransform();

btVector3 Forward;  // ???
btVector3 Right;    // ???
btVector3 Up;       // ???

_RigidBody->activate(true);
//
//  Move forward/backward
_RigidBody->applyCentralForce(Forward * 5);
_RigidBody->applyCentralForce(-Forward * 5);
//
//  Jump
_RigidBody->applyCentralForce(Up * 5);
//
//  Move left/right
_RigidBody->applyCentralForce(Right * 5);
_RigidBody->applyCentralForce(-Right * 5);

I also have a GLM model matrix which is essentially a copy of the bullet transformation matrix inside a glm::mat4 which I could use here instead and convert the resulting vector over to bullet but would much rather stay in bullet land for the entirety of this part.


Solution

  • You should always say explicitly, what library you are using. I assume, you use this.

    The operator() gives you the image of a vector under the transformation, so I assume, that the following does what you want:

    btVector3 Forward = Trans(btVector3{1,0,0});