glMultMatrixf(): rotation order?
If you create a matrix of your own with rotations in it and then multiply the transformation matrix, what order does opengl apply the transformations? My experiments have found that it applies x, y and z in that order, although I really wish it were Y, X, Z (heading/yaw, pitch, roll). I just wanted to confirm/deny my findings. B
When you multiply transformation matrices together, the new matrix does the transformations in the order that you multiplied them. So if you have three rotation matrices (let's call them mx, my, and mz), and you want to transform by them, just send them to glMultMatrix() in the order you want. i.e.
glMultMatrixf(my);
glMultMatrixf(mx);
glMultMatrixf(mz);
If you're doing the matrix multiplication yourself, you just need to do the multiplications in this order. So (assuming you've got a C++ matrix class with overloaded multiplication):
Now concat is a matrix that applies the three rotations in the order you want. This is pretty much the way OpenGL does things, too. It's one of the best features of using matrices, because one matrix can represent any number of transformations in a specific order.
glMultMatrixf(my);
glMultMatrixf(mx);
glMultMatrixf(mz);
If you're doing the matrix multiplication yourself, you just need to do the multiplications in this order. So (assuming you've got a C++ matrix class with overloaded multiplication):
Code:
//This should be an identity matrix.
Matrix concat();
//Concatenate y, x and z in that order.
concat *= my;
concat *= mx;
concat *= mz;
Now concat is a matrix that applies the three rotations in the order you want. This is pretty much the way OpenGL does things, too. It's one of the best features of using matrices, because one matrix can represent any number of transformations in a specific order.
Just to put confirmation to Jeff's comment, in my snowboarding game I multiply the Y rotation matrix by the X and Z and then transform the snowboarder model by the final matrix and it performs it in that order.
One trap for the unwary  OpenGL uses its matrices transposed from the way you would have learnt about them in math class. That means that if your math text says to do A * B * C, you really need to do C^T * B^T * A^T in OpenGL.
Check out "Viewing and Modeling Transformations" in chapt 3 of the redbook. Basically says:
glMatrixMode(GL_MODELVIEW);
glLoadIdentity;
glMultMatrixf(N);
glMultMatrixf(M);
glMultMatrixf(L);
glBegin(GL_POINTS);
glVertex3f(v);
glEnd();
which will do N * (M * (L * v))  that is the point v transformed by matrix L, then transformed by matrix M, then transformed by matrix N. That is if you conceptually think about it as being a point which is being transformed. However  you can also conceptualize it as having your base coordinate system which is what is being transformed  in which case you have your identity (base) which is then transformed by matrix N, which is then transformed by matrix M, which is then transformed by matrix L, and then point v is drawn in that new coordinate system. The code is the same obviously  its just two ways of thinking about it.
Also  while this article isnt specific to OpenGL's matrices (matrixes??), <http://www.gamasutra.com/features/200205...on_pfv.htm> is a great article on getting a handle on taking the guesswork out of using transformation matrixes (matrices??).
hth,
Codemattic
glMatrixMode(GL_MODELVIEW);
glLoadIdentity;
glMultMatrixf(N);
glMultMatrixf(M);
glMultMatrixf(L);
glBegin(GL_POINTS);
glVertex3f(v);
glEnd();
which will do N * (M * (L * v))  that is the point v transformed by matrix L, then transformed by matrix M, then transformed by matrix N. That is if you conceptually think about it as being a point which is being transformed. However  you can also conceptualize it as having your base coordinate system which is what is being transformed  in which case you have your identity (base) which is then transformed by matrix N, which is then transformed by matrix M, which is then transformed by matrix L, and then point v is drawn in that new coordinate system. The code is the same obviously  its just two ways of thinking about it.
Also  while this article isnt specific to OpenGL's matrices (matrixes??), <http://www.gamasutra.com/features/200205...on_pfv.htm> is a great article on getting a handle on taking the guesswork out of using transformation matrixes (matrices??).
hth,
Codemattic
Possibly Related Threads...
Thread:  Author  Replies:  Views:  Last Post  
OpenGL graphical data storage order question.  WhatMeWorry  3  4,255 
May 4, 2007 12:13 PM Last Post: tigakub 

glMultMatrixf and rotations  jSTIN  7  9,614 
Nov 25, 2003 04:56 AM Last Post: DoG 

Quaternion rotation > OpenGL rotation matrix?  DJBlufire  3  4,636 
Sep 6, 2003 08:34 PM Last Post: MattDiamond 

Drawing order with blending  Tobi  3  6,800 
May 10, 2002 12:31 AM Last Post: Tobi 