This topic is now archived and is closed to further replies.


Matrix Clarification Needed

Recommended Posts

Ok, ive looked at too many websites each telln me a different way to interpet an array representing a 4x4 matrix!! (im all cross-eyed now) I need clarification: I guess i know opengl uses "column/row" order, but as far as array access, im screwy. If I declare in a matrix class an array like so... float matrix[16]; Is the following the correct representation of this array: m0 m4 m8 m12 m1 m5 m9 m13 m2 m6 m10 m14 m3 m7 m11 m15 and... Rotation of X Axis = (m0, m1, m2) Rotation of Y Axis = (m4, m5, m6) Rotation of Z axis = (m8, m9, m10) Translation = (m12, m13, m14) and... (m3, m7, m11, m15) = (0, 0, 0, 1) What is confusing me is the order of the array. If i dont have the order correct, my rotations will be all wacked. But this should be a simple question for those that have created there own matrix class.

Share this post

Link to post
Share on other sites
I haven''t been looking so much into GL matrices, but since you''re making a float array[16] the order comes out like this:

m0, m1, m2, m3,
m4, m5, m6, m7,
m8, m9, m10,m11,

You just need to make a conversion function:
//Before you try this example, just try to copy your
// matrix right into the GL matrix and see what happends,if
//that worked then great! If not, try this conversion.

float myMatrix[16];
GLMATRIX glMatrix; //i dunno how they''re initialized

glMatrix.m0 = myMatrix[0];
glMatrix.m1 = myMatrix[4];
glMatrix.m2 = myMatrix[8];
glMatrix.m3 = myMatrix[12];

glMatrix.m4 = myMatrix[1];
glMatrix.m5 = myMatrix[5];
glMatrix.m6 = myMatrix[9];
glMatrix.m7 = myMatrix[13];

glMatrix.m8 = myMatrix[2];
glMatrix.m9 = myMatrix[6];
glMatrix.m10 = myMatrix[10];
glMatrix.m11 = myMatrix[14];

glMatrix.m12 = myMatrix[3];
glMatrix.m13 = myMatrix[7];
glMatrix.m14 = myMatrix[11];
glMatrix.m15 = myMatrix[15];

//There you have it
//You direct copy like this:

glMatrix.m0 = myMatrix[0]
glMatrix.m1 = myMatrix[1]
glMatrix.m2 = myMatrix[2]
glMatrix.m3 = myMatrix[3]
and so on..

//Gee, I wonder why it''s called DIRECT copy =D
//Anyway, check these out and come back if neither is


Share this post

Link to post
Share on other sites
Thats why I dont wanna do conversion!! I wanna make sure that I order my array the way that opengl is.

I just cant find a sight that CLEARLY STATES WHICH WAY IT IS.

...which is why I want someone whos made a matrix class with a float matrix_array[16].....ugg!

Share this post

Link to post
Share on other sites
Yes. Your matrix is arrayed properly for openGL.

I think I remember an extension that lets you switch the orientation of the matrices so you can do float matrix[4][4]; and have it work, but it''s a little foggy and not worth getting into.

Share this post

Link to post
Share on other sites
I agree about the matrix[4][4] approach, since the operations in C++ will be ack-basswards. Which is also why I posted since i DO SEE a lot of examples which do use the [4][4] approach. Thanks for the post though.

Share this post

Link to post
Share on other sites