Transferred from: http://www.cnblogs.com/soroman/archive/2008/03/21/1115571.html
Thinking: Matrices and transformations, and the use of matrices in DirectX and OpenGL
1. Matrix and Linear transformations: one by one correspondence
A matrix is a tool used to represent a linear transformation, which corresponds to a linear transformation of one by one.
Consider a linear transformation:
a11*x1 + a12*x2 + ... +a1n*xn = X1 '
a21*x1 + a22*x2 + ... +a2n*xn = X2 '
...
am1*x1 + am2*x2 + ... +amn*xn = XM '
Correspondingly, it is represented by a matrix:
|a11 A12 ... a1n | |x1| |x1 ' |
|a21 A22 ... a2n | |x2| |x2 ' |
|... | * |...| = |... |
|am1 AM2 ... amn | |xn| |xm ' |
Can also be expressed as follows:
|a11 A21 ... am1|
|a12 A22 ... am2|
|x1 x2...xn|*| ... | = |x1 ' x2 ' ... xm ' |
|a1n a2n ... amn|
There are 6 matrices involved. A[m*n],x[n*1],x ' [m*1] and X[1*n],a[n*m],x ' [1*m], respectively.
It can be understood that vector x (x1,x2,..., xn) becomes another vector x ' (x1 ', X2 ',..., xm ') after a transformation matrix a[m*n] or a[n*m].
2. Matrix notation: Row Matrix vs. column Matrix
The names of the row and column matrices are derived self-vector and column vectors.
In fact, the Matrix A[m*n] can be seen as a row matrix consisting of M n-dimensional row vectors, or as a column matrix of n m-dimensional column vectors.
where x[n*1]/x ' [m*1] is equivalent to the 1-n/m-dimensional column vector. X[1*n]/x ' [1*m] is equivalent to a row vector of 1 n/m dimensions.
The row matrix and column matrix are just two different representations that map a vector to a line of the matrix, which indicates that a vector is mapped to a column of the Matrix.
Essentially, the same linear transformation is represented. The matrix operation specifies that they can change the mapping relationship by a transpose operation.
3. Multiplication Order of matrices: pre-multiply or left-multiply vs. post-multiply or right-multiply
It is important to note that the two different representations correspond to different sequence of operations:
If a column vector is transformed, the transformation matrix (row matrix/vectors) must appear on the left side of multiplication sign, which is pre-multiply, which is either a forward or a left-multiply.
If a row vector is transformed, the transformation matrix (column matrix/vectors) must appear on the right side of multiplication sign, that is, post-multiply, which is called a back or right multiply.
is generally not mistaken, because the matrix multiplication nature determines the same number of neive matrix to multiply. As to why this is the rule, why multiply the row vector by the column vector or column vector multiplied by the row vector??? Think about it...
So the left or right multiplication is related to the representation of the transformed vector, not the storage order.
4. Storage order of matrices: priority storage by row vs. priority storage By Column
When it comes to using matrices in your computer, you first encounter the problem of storage matrices.
Because the computer storage space is sequential, how to store A[m*n] m*n elements is a problem, generally there are two kinds: priority storage by row and priority storage by column.
Row-major: The order in which the AMN is saved into A11,a12,...,.
Column-major: The order in which the AMN is saved into A11,a21,...,.
So here's the problem, give you a collection of well-stored matrix elements, you don't know how to read the elements into a matrix, like you don't know A12 should be on a few rows.
Therefore, each system has its own rules, such as what rules are stored in what rules to read. DX uses ROW-MAJOR,OGL to use Column-major. That is, the same matrix a[m*n] The storage sequence in DX and OGL is not the same, which brings the hassle of inter-system conversion.
However, a coincidence is that: in DX, the dot/vector is represented by the row vector, so the corresponding transformation matrix is column matrix/vectors, and in OGL, the point/vector is represented by the column vector, so the corresponding transformation matrix is row Matrix/vectors. So, if the matrix transformation of a[4*4] is applied to a vector x (x1,x2,x3,1) or point (X (x1,x2,x3,1)) in the DX, it is x ' = x (x1,x2,x3,1) * A[4*4], Because of the use of row-major, its storage sequence is A11,a12,..., a43,a44. In OGL, do the same vector or point transformation, because it uses row matrix/vectors, and its applied transformation matrix should be a ' [4*4] = a[4*4] (' means transpose/transpose), that is x ' = A ' [4*4] * x ' (x1,x2,x3,1 ), but because of column-major, its storage sequence is just as A11,A12,..., a43,a44!!!
So in fact, for DX and OGL, the same transformation, the stored matrix element sequence is the same. For example, the 13,14,15 element stores the translation change Amount Deltaz,deltay,deltaz.
Refs:
Http://mathworld.wolfram.com/Matrix.html
http://www.gamedev.net/community/forums/topic.asp?topic_id=321862
Thinking: Matrices and transformations, and the use of matrices in DirectX and OpenGL: left-multiply/right-multiply, row-first/column-first,...