# extract translation/ euler rotation from modelview

Hi,

I need for an augmented reality application convert the finded opengl modelview (I have a find a way to have a modelview … but it’s not exact … so to understand I hopes to recover the translation and an human readable rotation list). Is there an easy way to convert my modelview to a translation vector and the rotation angles in order to replace the modelview by a translation and 3 rotations ?

Translations can be read directly out of the modelview matrix. Assuming the matrix is dimensioned [16]. It’s either the 3,7,11th elements, or the 12,13,14 elements. Don’t remember which. Just print out the matrix and it will be obvious.

For an Euler angle sequence you work with the upper 3x3 part of the modelview matrix (elements 0,1,2, 4,5,6, 8,9,10). Look at the Wikipedia article on Euler angles. Towards the bottom they give you matrices corresponding to any sequence of Euler rotations. Pick the sequence you like. The corresponding matrix shows you how to back out the 3 Euler angles.

Looks pretty straightforward, though I admit I haven’t tried it.

It’s either the 3,7,11th elements, or the 12,13,14 elements.

Assuming a linear array of floats and the matrix has been obtained from OpenGL, then the translation parts are 12,13,14.

Will the translation elements be affected by calls to glScale*?

Try printing out the matrix elements with and without glScale in your code.
Also try putting glScale before and after retrieving the matrix.

Just tested it, the answer is no: scaling affects the rotation elements, but not the translation column.

This depends on the order in which you perform the operations. Try printing the result of S * T and the result of T * S

Edit: I answered in a two months old thread, nice. Sorry for the up.

You can read about SVD Singular Value Decompositions to get à grip on more advanced methods to decompose a matrix.