# Matrix to quat and back

This topic is 4098 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

i have a 4x4 matrix class defined as such: rows[0] = vec4(m00, m01, m02, m03); rows[1] = vec4(m10, m11, m12, m13); rows[2] = vec4(m20, m21, m22, m23); rows[3] = vec4(m30, m31, m32, m33); i can not get my quat class to function properly going from quat to matrix and then back to matrix. i am testing by first creating my rotation, like i do for all other rotations in my engine. i then take that matrix and convert to a quat. i am assuming that quatToMatrix should return the original rotation matrix. mine do not. can someone help please. if it helps i can post my two functions, quatToMatrix and matrixToQuat functions if that helps. thanks to all

##### Share on other sites
It would help to post your code, and some example results.

There could be any of a number of issues (handedness problem, scale in matrix, translation in matrix etc. etc.)

##### Share on other sites
Rotation is represented by a 3x3 matrix and you are using a 4x4. Would that be the problem?

##### Share on other sites
i am using a 4x4 matrix, as it is my base matrix class for use in my engine. what i am doing is, trying to do skinned mesh. where i get the rotation keys from the model, in this case ms3d file, and then convert them into a 4x4 matrix class so that i can send to the vertex shader to do the transformation.

however, i figured out what my problem with teh quat class was, so now

mat4 rotation = rotateXYZ( PI, PI, PI );

quat q = matrixToQuat( rotation );

mat4 rotation2 = quatToMatrix( q );

i now have the conversion proper, so that rotation == rotation2

so the problem in my skinning code is elsewhere.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 13
• 14
• 10
• 9
• 11
• ### Forum Statistics

• Total Topics
634096
• Total Posts
3015491
×