# OGLs Matrix layout

OK, I have got a problem in finding out, which is the correct Matrix layout in OpenGL (or better the native one?).

All of my Matrix functions use the following layout:

[ 1][ 2][ 3][ 4]
[ 5][ 6][ 7][ 8]
[ 9][10][11][12]
[13][14][15][16]

And are declared as:
float fMatrix[16];

The index of the element is simple element - 1.

If I query OGL for the Modelview Matrix, the translations are in the elements 13, 14 and 15.

What confuses me is that the layout, mentioned in the redbook is like that:

[ 1][ 5][ 9][13]
[ 2][ 6][10][14]
[ 3][ 7][11][15]
[ 4][ 8][12][16]

The Matrix is declared like mine is:
float fMatrix[16];

Perhaps that´s a beginner question (sorry then), but I´m confused now .

Diapolo

It’s all about how you see it. Choose the layout you feel most comfortable with, but make sure you create your matrix library thereafter.

For example, a translation matrix in OpenGL looks like this,

1 0 0 x
0 1 0 y
0 0 1 z
0 0 0 1

where the elements are indexed like this,

1 5 9 13
2 6 10 14
3 7 11 15
4 8 12 16

As you can see, translation is located at 13-15. Now, if you use the transposed version of that translation matrix (x, y and z to the left in the bottom row), you must also transpose the index layout, making translation still located at index 13-15.

A matrix in OpenGL is a one sequence of 16 elements mapped in a cetrain way (for example, 13-15 for translation). How YOU translate this into a 2D layout is up to you.

What still confuses me is the following.
Look at the Matrix layout, like you posted it. If you want to access the translation part via the array index you have to use 3, 7 and 11 as index for elements 13, 14 and 15.

So I think how I do it, it is more straight forward (I can use element - 1 as index), or did I overlook something here?

Diapolo

Look at the Matrix layout, like you posted it. If you want to access the translation part via the array index you have to use 3, 7 and 11 as index for elements 13, 14 and 15.

Huh? You use index 12, 13 and 14 to access the translation part in my matrix. Subtract one from all numbers in my matrix and you have the offset in the array.

OK, wait … so the content of our matrices are identical (the indices too: element - 1) and ONLY the 2D view of the matrix differs?

That´s what you said about 2D layout is up to me .

Oh damn, I feel so stupid now .

Diapolo

[This message has been edited by Diapolo (edited 11-21-2002).]