Skip to main content
GameDev.net gamedev.net
🔒 Locked

Row/Column major matrices

Started by Corrail Dec 30, 2003 at 12:04 PM 0 replies 750+ views
Original Post
Corrail
Corrail
Hi all! Just wanted to ask how column/row major matrices are defined. 1 4 9 5 6 7 4 2 1 float mat[9]; mat[0] = 1; mat[1] = 4; mat[2] = 9; mat[3] = 5; mat[4] = 6; mat[5] = 7; mat[6] = 4; mat[7] = 2; mat[8] = 1; Is mat a row or a column major matrix? Which matrices does OpenGL use? -------------------------------------------------------- There is a theory which states that if ever anybody discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable. There is another theory which states that this has already happened... [edited by - Corrail on December 30, 2003 1:06:04 PM]
--------------------------------------------------------There is a theory which states that if ever anybody discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable.There is another theory which states that this has already happened...
chawk
chawk
That's a row-major matrix. All arrays are 'row-major' in a sense since increasing index values would take you horizontally across a row. When you pass an array to an OpenGL matrix-related function, it'll interpret the array in a column-major fashion as such:

float mat[9];

mat[0] = 1;
mat[1] = 4;
mat[2] = 9;
mat[3] = 5;
mat[4] = 6;
mat[5] = 7;
mat[6] = 4;
mat[7] = 2;
mat[8] = 1;

would produce a matrix interpreted as

1 5 4
4 6 2
9 7 1

Don't think of a row-major and column-major matrix as being stored differently in memory, they're not, it's just simply how they're interpreted. We're used to reading from index 0 to n-1, say, and defining that as row 0. OpenGL reads index 0 to n-1 and defines that as column 0.

edit: spelling

[edited by - chawk on December 30, 2003 1:46:48 PM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.