Get Rotation in MotionState

Post Reply
Registred
Posts: 3
Joined: Mon Feb 03, 2014 11:06 am

Get Rotation in MotionState

Post by Registred »

Hey,

I'm trying to get the rotation of an object from the btTransform parameter in the setWorldTransform method of a motion state.
Currently I'm using this code:

Code: Select all

void MyMotionState::setWorldTransform(const btTransform &worldTrans)
{
	btQuaternion rotation = worldTrans.getRotation();
        MyQuaternion orientation(rotation.x(), rotation.y(), rotation.z(), rotation.w());

        ...
}
When I apply this rotation to my 3D obejcts, the rotation is incorrect. A scale is also applied (I have no idea how this is possible).
When using worldTrans.getOpenGLMatrix() everything works fine, but I need to seperate the rotation from the translation, so this is not a possibilty.
Do I have to somehow apply the worldTrans.getRotation() quaternion with the worldTransform.getBasis() matrix?
What could be the cause for the incorrect rotations?

Just for clarity:
MyQuaternion is a simple class with no functionality and just stores 4 floats. I then create a glm::quat with it (by simply passing x, y, z and w) and then pass it to the glm::mat4_cast() function when rendering.
Greetings
c6burns
Posts: 149
Joined: Fri May 24, 2013 6:08 am

Re: Get Rotation in MotionState

Post by c6burns »

Sanity check, you are passing params in the order (w, x, y, z) and not (x, y, z, w) ?
Registred
Posts: 3
Joined: Mon Feb 03, 2014 11:06 am

Re: Get Rotation in MotionState

Post by Registred »

Thanks for your answer!

Yes, order should be right, the constructor of MyQuaternion takes w as the last param.
Registred
Posts: 3
Joined: Mon Feb 03, 2014 11:06 am

Re: Get Rotation in MotionState

Post by Registred »

update:
The issue should somehow related with the row and column major order of the matrix. I compared the 2 matrices (the one of the .getOpenGLMatrix() function and the one I calculate with GLM) and found that they are flipped (one is row major, the other column major).
I found this thread on the web which should be exactly my problem.

http://stackoverflow.com/questions/1220 ... jor-matrix

But I somehow don't get what the solution to this is now.
Post Reply