OpenGL Matrix to XYZ rotation and back

I need to separate the x,y and z rotation components out of a matrix which contains no scaling factor. Therefore I found this website:
www.robertblum.com/articles/category/math/

I tried to implement it that way, but when I use the three results to create the same matrix again, I don’t get the original matrix back - some values are (more than slightly) different or with inverted sign.

Probably I just did a mistake. If anyone can fix it out of this code:

``````		rotVals.x = atan2( m_fMVMatrix[9], m_fMVMatrix[10]);
rotVals.y = asin( -m_fMVMatrix[8] );
rotVals.z = atan2( m_fMVMatrix[4], m_fMVMatrix[0]);

GLdouble mat[16] =
{	cos(rotVals.y)*cos(rotVals.z),
(cos(rotVals.z)*sin(rotVals.x)*sin(rotVals.y)) - (sin(rotVals.z)*cos(rotVals.x)),
(cos(rotVals.x)*cos(rotVals.z)*sin(rotVals.y)) + (sin(rotVals.x)*sin(rotVals.z)),
0,

cos(rotVals.y)*sin(rotVals.z),
(sin(rotVals.x)*sin(rotVals.y)*sin(rotVals.z)) + (cos(rotVals.x)*cos(rotVals.z)),
(cos(rotVals.x)*sin(rotVals.y)*cos(rotVals.z)) - (sin(rotVals.x)*cos(rotVals.z)),
0,

-sin(rotVals.y),
-sin(rotVals.x)*cos(rotVals.y),
cos(rotVals.x)*cos(rotVals.y),
0,

pos.x,
pos.y,
pos.z,
1.0
};
``````

it would be great!

ok - I got it - there were some comments on the website - the author did a small error. Now it works…

There was a Saint Anselm, y’know.

anselm von canterbury. did you hear about him in your catholic priest seminar ?

he has been my arch enemy for the last four hundred years, body.

400 years, and you couldn’t defeat him?
if you need some help…

400 years on a part-time basis - I can only manage less than an hour a week devoted to saint hunting. Ideally I’d be a professional saint hunter, but the pay is rubbish at the moment, partly due to it’s popularity with graduates - it seems experience counts for nothing these days. Now back in the day, Cromwell paid well.

Those graduates can’t find their ass with both hands and a map. They should stick with the professional saint hunters, at least to lead the graduates.

Damn straight, dorbie. Damn straight.