glMultMatrixf(): rotation order?

Post: #1
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
Quote this message in a reply
Jeff Binder
Post: #2
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.


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):

//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.
Quote this message in a reply
Posts: 345
Joined: 2002.04
Post: #3
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.
Quote this message in a reply
Posts: 5,143
Joined: 2002.04
Post: #4
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.
Quote this message in a reply
Posts: 304
Joined: 2002.04
Post: #5
Check out "Viewing and Modeling Transformations" in chapt 3 of the redbook. Basically says:


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??), <> is a great article on getting a handle on taking the guesswork out of using transformation matrixes (matrices??).

Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  OpenGL graphical data storage order question. WhatMeWorry 3 3,255 May 4, 2007 12:13 PM
Last Post: tigakub
  glMultMatrixf and rotations jSTIN 7 6,670 Nov 25, 2003 04:56 AM
Last Post: DoG
  Quaternion rotation -&gt; OpenGL rotation matrix? DJBlufire 3 3,738 Sep 6, 2003 08:34 PM
Last Post: MattDiamond
  Drawing order with blending Tobi 3 5,590 May 10, 2002 12:31 AM
Last Post: Tobi