Jump to content
  • Advertisement
Sign in to follow this  
ade-the-heat

OpenGL opengl matrices dumb question

This topic is 4905 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

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
OpenGL matrices are column major, but it's not worth the effort having to convert them from the single dimentional array they come as.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

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!