PDA

View Full Version : OpenGL Matrix to XYZ rotation and back



AnselmG
01-10-2007, 03:57 AM
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/ (http://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!

AnselmG
01-10-2007, 04:05 AM
ok - I got it - there were some comments on the website - the author did a small error. Now it works...

knackered
01-11-2007, 11:59 PM
There was a Saint Anselm, y'know.

RigidBody
01-12-2007, 12:11 AM
anselm von canterbury. did you hear about him in your catholic priest seminar ;) ?

knackered
01-12-2007, 01:45 AM
he has been my arch enemy for the last four hundred years, body.

RigidBody
01-12-2007, 01:55 AM
400 years, and you couldn't defeat him?
if you need some help...

knackered
01-12-2007, 04:46 AM
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.

dorbie
01-12-2007, 11:39 AM
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.

knackered
01-12-2007, 01:14 PM
Damn straight, dorbie. Damn straight.