opengl matrices dumb question

Started by
2 comments, last by Zakwayda 19 years, 1 month ago
I'm going round in circles and I need someone to help! take an ordinary matrix eg 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 To store in an array in c we use: float mymatrix[4[4]={1,2,3,4}, {5,6,7,8}, ...., {13, 14, 15, 16}} However, opengl is column major so to use the above matrix for opengl we need to have the following: float mymatrix[4[4]={1,5,9,13}, {2,6,10,14}, ...., {4, 8, 12, 16}} Is this correct ? cheers Ade
Advertisement
I always just store my matrices in a single dimension array with 16 elements.
That way [0] through [3] always corresponds to the first row in an opengl matrice.
Author Freeworld3Dhttp://www.freeworld3d.org
OpenGL matrices are column major, but it's not worth the effort having to convert them from the single dimentional array they come as.
To the OP: looks like you've got it right. As has been mentioned, OpenGL matrices are column-major, so are laid out like this:

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

With a 2d array, the i-j inidices are:

00 01 02 03
10 11 12 13
20 21 22 23
30 31 32 33

So you can see how the 1d array maps to the 2d array. Aside from the 1-based indexing, this is what you had in your original post.

Remember also that OpenGL uses column vectors rather than row vectors, so regardless of whether the matrix is column or row major, the axes and translation are arranged in the matrix like this:

xx yx zx tx
xy yy zy ty
xz yz zz tz
0 0 0 1

This topic is closed to new replies.

Advertisement