Got some idea with my class of matrix operation facilitated by OpenGL original pipeline.
Notice that the matrix in OpenGL is column-major which represents the following matrix:
a column-major model-view matrix(fetched from OpenGL):
row 0: Xx Xy Xz Xw
row 1: Yx Yy Yz Yw
row 2: Zx Zy Zz Zw
row 3: Tx Ty Tz Tw
row 0: Xx Xy Xz Xw
row 1: Yx Yy Yz Yw
row 2: Zx Zy Zz Zw
row 3: Tx Ty Tz Tw
is the sequence in C/C++ if a model-view matrix is fetched from OpenGL because of the column-major
sequence in OpenGL. If in a row-major matrix, such as in DirectX or C++, this matrix should be
like this:
sequence in OpenGL. If in a row-major matrix, such as in DirectX or C++, this matrix should be
like this:
a row-major matrix we usually used in C/C++:
row 0: Xx Yx Zx Tx
row 1: Xy Yy Zy Ty
row 2: Xz Yz Zz Yz
row 3: Xw Yw Zw Tw
row 0: Xx Yx Zx Tx
row 1: Xy Yy Zy Ty
row 2: Xz Yz Zz Yz
row 3: Xw Yw Zw Tw
So, if you wish to apply a transformation with no errors or you don't want a transformation you
are not trying to have in OpenGL, use the 1st matrix form.
In C/C++, a 1 dimension array for being the matrix can be used in OpenGL with the right form
should be like:
are not trying to have in OpenGL, use the 1st matrix form.
In C/C++, a 1 dimension array for being the matrix can be used in OpenGL with the right form
should be like:
GLfloat modelViewMatrix = { Xx, Xy, Xz, Xw,
Yx, Yy, Yz, Yw,
Zx, Zy, Zz, Zw,
Tx, Ty, Tz, Tw};
Looks weird, huh? But that's it in GL, and we'd better get used to it and keep focused while applying custom transformation!
/****************************************************************************************/
But in GLSL use row-major ways to select certain element.
if a matrix is mat4 mat = {1.0, 2.0, 3.0, 1.0,
4.0, 5.0, 6.0, 7.0,
8.0, 9.0, 10.0, 11.0,
12.0, 13.0, 14.0, 15.0};
select 12.0 by using mat[3][0], Where 3 as column index and 0 as row index, like mat[col][row]. Column idx in front of row idx.
Yx, Yy, Yz, Yw,
Zx, Zy, Zz, Zw,
Tx, Ty, Tz, Tw};
Looks weird, huh? But that's it in GL, and we'd better get used to it and keep focused while applying custom transformation!
/****************************************************************************************/
But in GLSL use row-major ways to select certain element.
if a matrix is mat4 mat = {1.0, 2.0, 3.0, 1.0,
4.0, 5.0, 6.0, 7.0,
8.0, 9.0, 10.0, 11.0,
12.0, 13.0, 14.0, 15.0};
select 12.0 by using mat[3][0], Where 3 as column index and 0 as row index, like mat[col][row]. Column idx in front of row idx.