Matrix Clarification Needed
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.
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,
m12,m13,m14,m15.
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
//successfull.
Js
m0, m1, m2, m3,
m4, m5, m6, m7,
m8, m9, m10,m11,
m12,m13,m14,m15.
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
//successfull.
Js
Js
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!

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!
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement