Jump to content
• Advertisement

# OpenGL Question about the matrix in Opengl

This topic is 4237 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

## Recommended Posts

Hi all! I am new comer in opengl. I have trouble with the glGetFloatv(GL_MODELVIEW_MATRIX, lastmatrix); I did a simple test program like this: glLoadIdentity(); glRotatef(45,0,0,1); glGetFloatv(GL_MODELVIEW_MATRIX, lastmatrix); // the value of the lastmatrix is { 0.70710677, 0.70710677 , 0 ,0 -0.70710677 , 0.70710677 , 0 ,0 0.0000000000, 0.00000000, 1 ,0 0.0000000000, 0.00000000, 0 ,1} But I thought it should be { 0.70710677, -0.70710677 , 0 ,0 0.70710677 , 0.70710677 , 0 , 0 0.0000000000, 0.00000000, 1 ,0 0.0000000000, 0.00000000, 0 ,1} What is wrong with this? I get the transpose of the matrix I want. Then I use another program to test, it is all right; // glLoadIdentity(); GLfloat lastmatrix[16] = {2,5,0,1, 0,1,2, 2, 5,4,4,4, 9,5,2,0}; glMultMatrixf(lastmatrix); glGetFloatv(GL_MODELVIEW_MATRIX, lastmatrix); then I get the right answer, the value of the lastmatrix is {2,5,0,1, 0,1,2, 2, 5,4,4,4, 9,5,2,0}; So can anybody tell me what is wrong with this? Thanks a lot!

#### Share this post

##### Share on other sites
Advertisement
guess u are a directx guy, in OpenGL matrices are all in column major order.. that is when u put something like

float mat[16] = {2,3,4,5,
6,7,8,9,
......
};

it actually means that

2,3,4,5 is the first COLUMN of the matrix, i.e.

|2,6
|3,7
|4,8
|5,9

#### Share this post

##### Share on other sites
pengsenl,
OpenGL uses column-major format for matrix. So 4 elements in a column are filled first then move on the next column.

#### Share this post

##### Share on other sites
Thanks a lot! But i still want to know if I multiply the current matrix M by another matrix like this
glLoadIdentity();
GLfloat A[16] = {2,5,0,1,
0,1,2, 2,
5,4,4,4,
9,5,2,0};
glMultMatrixf(A);
Then how opengl do it? the result is M*A' or M*A?
If I use the glGetFloatv(GL_MODELVIEW_MATRIX, m_lastMatrix); It return the matrix in column order or in row order?

#### Share this post

##### Share on other sites
It's M*A of course. Just silly to transpose the matrix before multiplication. Same with glGetFloat; it returns the matrix, not it's transpose.

But then again, you're probably still confused about what the linear layout of elements really are, compared to the transposed layout.

A matrix M with elements like this:
    | a, b, c, d |M = | e, f, g, h |    | i, j, k, l |    | m, n, o, p |

is defined as a one-dimensional array in C as
float M[16] = {a, e, i, m, b, f, j, n, c, g, k, l, d, h, l, p};

From this layout and the corresponding mapping, you can determing how multiplication behaves in OpenGL.

Ok! thanks !

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
2. 2
Rutin
22
3. 3
4. 4
JoeJ
11
5. 5
• Advertisement

• 14
• 30
• 13
• 11
• 11
• ### Forum Statistics

• Total Topics
631776
• Total Posts
3002304
×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!