Yes..but I already knew about most of the matrix part from way back when. I just didn't know how to find the inverse...if there was one...to a matrix. Most texts called it out of the scope of the article which really got old after awhile.
www.gamedev.net has an excellent explanation of why and how matrices work but you can figure it out on your own.
If you look at a vector it is in reality a matrix.
V=[x y z]
A matrix is simply an array of vectors.
A square matrix is one who has equal number of rows and columns.
For instance a 3x3 matrix.
M=
[m11 m12 m13]
[m21 m22 m23]
[m31 m32 m33]
The diagonal of this matrix is m11 m22 m33.
But here is the beauty of a matrix -> matrix multiplication or concatenation of matrices.
We all know that transformation is a linear process. Each transform must be done in a certain order (somewhat) and each one requires quite a bit of multiplication. Wouldn't it be nice to be able to multiply once by already transformed values? This would transform your vertex with one multiply. Well with matrices you can do just that. You start with an identity matrix. Then you create a translation matrix. Then you do rotations about x,y,z or arbitrary axes..whichever you choose. Multiply the translation matrix by the rotation matrix and you get a new matrix which is the result of the multiplication. Now you can use this new matrix as one of the operands in your next multiplication. Now you can do scaling on x,y,z or arbitrary axes. Multiply them together and you have effectively done a world transform.
The first step is from object space to inertial space. This a non-affine transform or simply a transform that does not have translation in it. So scaling and rotation are all non-affine transforms.
To transform a vertex from object space to inertial space simply concatentate the rotation matrix with the scaling matrix and then multiply your vector by the concatenated matrix.
Now you can perform translation which will 'move' your object to the correct world coordinates. Multiply this matrix by the concatenated matrix from above and you have done a world transform.
Now you need to construct a projection matrix to project from world space to camera space and then you need a clip matrix to transform from camera space to clip space.
Confused? It's really not too hard once you do it.
Here is how you multipy a scalar by a matrix.
kM=
[m11 m12 m13]
[m21 m22 m23]
[m31 m32 m33]
=
[km11 km12 km13]
[km21 km22 km23]
[km31 km32 km33]
Here is how you multiply two matrices together.
The number of columns in A must match the number of rows in B or AB is undefined - they cannot be multiplied together.
Here is how you multiply a matrix together.
3D Math Primer for Graphics and Game Development. Fletcher
Dunn and Ian Parberry
...For each element C(ij) locate row i in A and column j in B. Multiply the corresponding elements of the row and column, and sum the products. (Equivalent to the dot product of row i in A with column j in B.)
A=
[a11 a12]
[
a21 a22]
[a31 a32]
[a41 a42]
B=
[b11 b12 b13
b14 b15]
[b21 b22 b23
b24 b25]
AB=
[c11 c12 c13 c14 c15]
[c21 c22 c23
c24 c25]
[c31 c32 c33 c34 c35]
[c41 c42 c43 c44 c45]
c24=
a21b14 +
a22b24;
Here is a 3x3 example:
AB=
[a11 a12 a13] [b11 b12 b13]
[a21 a22 a23] [b21 b22 b23]
[a31 a32 a33] [b31 b32 b33]
=
[a11b11+a12b21+a13b31 a11b12+a12b22+a13b32 a11b13+a12b23+a13b33]
[a21b11+a22b21+a23b31 a21b12+a22b22+a23b32 a21b13+a22b23+a23b33]
[a31b11+a32b21+a33b31 a31b12+a32b22+a33b32 a31b13+a32b23+a33b33]
I suggest purchasing a book from amazon.com - the one I quoted from is an excellent book. As I said though www.gamedev.net has excellent tutorials on matrices.
In order to understand why matrices transform vertexes you must manually work out the multiplication.
Here is how you multiply a vector by a matrix (code tags are simply to preserve spacing).
Code:
[x y z]*[m11 m12 m13]
[m21 m22 m23]
[m31 m32 m33]
=
[xm11+ym21+zm31 xm12+ym22+zm32 xm13+ym23+zm33]
Here are some simple matrices to help you get started:
As to why we use 4x4 matrices in 3D math instead of 3x3 - it's simply a mathematical trick to allow us to put a translation vector into the mix. Without the 4x4 there would be no way to do this. Since we want our pipeline to be relatively similar in operation at each stage...we use 4x4 matrices.
Identity matrix
I=
[1.0 0.0 0.0 0.0]
[0.0 1.0 0.0 0.0]
[0.0 0.0 1.0 0.0]
[0.0 0.0 0.0 1.0]
Multiply matrix A by this matrix results in matrix A. Or more succintly:
AI=A
Scaling matrix - scale on x y z only
s=[x y z w] where w=1.0
M(s)=
[s.x 0.0 0.0 0.0]
[0.0 s.y 0.0 0.0]
[0.0 0 0.s.z 0.0]
[0.0 0.0 0.0 s.w]
If you multiply vector v by this matrix you will get v=[(s.x)x (s.y)y (s.z)z 1.0]
Translation matrix
t=[x y z w] where w=1.0
M(t)=
[1.0 0.0 0.0 0.0]
[0.0 1.0 0.0 0.0]
[0.0 0.0 1.0 0.0]
[t.x t.y t.z t.w]
And finally some C code to multiply these matrices as 2D arrays. However, I rarely use 2D arrays or 1D arrays for matrices.
Code:
//Multiplies two 4x4 matrices together leaving the result in r[]
void MatrixMultiply4x4(float m1[4][4],float m2[4][4],float r[4][4])
{
for (int i=0;i<4;i++)
{
for (int j=0;j<4;j++)
{
r[i][j]=0.0f;
for (int k=0;k<4;k++)
{
r[i][j]+=m1[i][k]*m2[k][j];
}
}
}
}