Matrix Multiplication Part 3: Matrix Transformation Tutorial
Table of Contents
- Introduction
- Math Prerequisites
- Importance of Correct Transformations
- What a Matrix Represents
- Matrix Multiplication
- Transforming a Vector by a Matrix
- Object Space Transformations
- Camera Transformations
- Inverse Transformations
- Hierarchical Transformations
- Precision
- Conclusion
Matrix Multiplication
There are two matrix operations which we will use in our
matrix transformations, multiplying (concatenating) two matrices, and
transforming a vector by a matrix. We will now examine the first of
these two operations, matrix multiplication.
Matrix multiplication is the operation by which one matrix is
transformed by another. A very important thing to remember is that
matrix multiplication is not commutative. That is, [a] * [b] != [b] *
[a]. For now, it will suffice to say that a matrix multiplication
stores the results of the sum of the products of matrix rows and
columns. Here is some example code of a matrix multiplication routine
which multiplies matrix [a] * matrix [b], then copies the result to
matrix a.
void matmult(float a[4][4], float b[4][4])
{
float temp[4][4]; // temporary matrix for storing result
int i, j; // row and column counters
for (j = 0; j < 4; j++) // transform by columns first
for (i = 0; i < 4; i++) // then by rows
temp[i][j] = a[i][0] * b[0][j] + a[i][1] * b[1][j] +
a[i][2] * b[2][j] + a[i][3] * b[3][j];
for (i = 0; i < 4; i++) // copy result matrix into matrix a
for (j = 0; j < 4; j++)
a[i][j] = temp[i][j];
}
I have been informed that there is a faster way of multiplying
matrices, which involves taking the dot product of rows and columns.
However, I have yet to implement such a method, so I will not discuss
it here at this time.
|