PDA

View Full Version : extract rotations and translations from matrix4x4

deshan
05-31-2011, 12:04 PM
Hi
I have a matrix which I inputs to the glMultMatrixf() function.
Now I am in a problem of extract rotaions and transformations
from this matrix, could you please tell me how to do that?

void draw(float* matrix4x4)
{
glMultMatrixf(matrix4x4);

//1. extract rotations roll, pitch and yaw from matrix4x4
//2. extract translation from matrix4x4
}

Thank you

Alfonse Reinheart
05-31-2011, 01:29 PM
extract rotations roll, pitch and yaw from matrix4x4

It's easier to just keep track of those yourself. You did apply yaw, pitch, and rolls to generate the matrix, so just keep them stored in a variable.

Remember, YPR is not unique for any particular orientation. Each rotation matrix uniquely describes an orientation, but there are multiple YPR's that will provide the same orientation. So even if you did decompose matrix4x4 back into YPR, you're not guaranteed to come up with the same YPRs that you used to generate it in the first place.

As for the translation, that's easy. matrix4x4[12], [13], and [14] is the translation.

NeuroFuzzy
05-31-2011, 05:48 PM
Yes... if you have an alternative, just store the variables.

I have had to extract angles from a matrix before, and it's not very fun. I had a limb system, so I multiplied the child's world matrix by the parent's world matrix, but I had to pass the resulting rotation into an API accepting euler angles (in Zrot*Yrot*Xrot*Vector format). I found a paper, which answered my question directly. it works with the format I described above, but can be adapted.
this is the paper:
http://www.gregslabaugh.name/publications/euler.pdf

V-man
06-01-2011, 05:40 AM
My library has a function called glhExtractAnglesFromRotationMatrixf2.
You must make sure that it is a rotation matrix. Use glhIsMatrixRotationMatrixf.
Set matrix4x4[12], [13], and [14] to 0.0 before using glhExtractAnglesFromRotationMatrixf2.