# What a Matrix Represent Part 2: 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
### What a Matrix Represents
Before we continue, it will help you greatly to understand what
the values in a matrix represent. A 4x4 matrix contains 4 vectors,
which represent the world space coordinates of the x, y and z unit
axis vectors, and the world space coordinate which is the origin of
these axis vectors.
```
X Y Z C
+= =+
| += =+ += =+ += =+ += += |
| | | | | | | | | |
| | X | | X | | X | | 0 | |
| | | | | | | | | |
| | | | | | | | | |
| | Y | | Y | | Y | | 0 | |
| | | | | | | | | |
| | | | | | | | | |
| | Z | | Z | | Z | | 0 | |
| += =+ += =+ += =+ | | |
| +===============+ | | |
O | X Y Z | 1 | |
| +===============+ += =+ |
+= =+
```
The X column contains the world space coordinates of the local X axis
The Y column contains the world space coordinates of the local Y axis
The Z column contains the world space coordinates of the local Z axis
These vectors are unit vectors. A unit vector is a vector whose
magnitude is 1. Basically, unit vectors are used to define
directions, when magnitude is not really important.
The C column always contains the specified values
The O row contains the world space coordinates of the object's origin
You can make life easy for yourself by storing matrices which contain
axis information in each object. I keep two matrices for every
object; omatrix, which stores the object space matrix, and ematrix,
which stores the eyespace matrix for the object.
A special matrix is the identity matrix:
```
+= =+
| += =+ += =+ += =+ += += |
| | | | | | | | | |
| | 1 | | 0 | | 0 | | 0 | |
| | | | | | | | | |
| | | | | | | | | |
| | 0 | | 1 | | 0 | | 0 | |
| | | | | | | | | |
| | | | | | | | | |
| | 0 | | 0 | | 1 | | 0 | |
| += =+ += =+ += =+ | | |
| +===============+ | | |
| 0 0 0 | 1 | |
| +===============+ += =+ |
+= =+
```
Notice why the identity matrix is special? The identity matrix
represents a set of object axes that are aligned with the world axes.
Remember that the vectors stored in the matrix are unit vectors. Now,
because the world x coordinate of the local x axis is 1, the world y
and z coordinates of the local x axis are 0, and the origin vector
is [0, 0, 0], the local x axis lies directly on the world x axis. The
same is true for the local y and z axes.
The other special property of the identity matrix is given away in its
name. If you are familiar with math, you know that there are identity
elements in the set of any arithmetic operation. When an binary
operation is performed on some operand and the identity element of the
set, the operand is the result of the operation. For example,
identity elements for multiplication and division are 1, and identity
elements for addition and subtraction are 0. x + 0 = x; x - 0 = x; x
* 1 = x; x / 1 = x. Similarly, [x] * [identity] = [x] (I will denote
matrices in brackets [] throughout this doc, for example [x] is
"matrix x"). |