Matrix arithmetic and coordinate system.
Information
Coordinate systems
Coordinate systems are used to describe the locations of points in space.
In m3g the orthographic coordinate system is used. In an orthographic coordinate system, the X, Y and Z axis are perpendicular to each other. The righthand rule is used, with +Y (index finger) being up, +X (thumb) horizontal to the right, and +Z (middle) directed toward the viewer.
All angles or rotational representations are in degrees. A positive rotation is counter clockwise.
In m3g, three coordinate systems plays an important role:
 World coordinate system.
Is the base on which all other coordinates are being defined.
 Camera coordinate system.
This coordinate system is aligned with the eye or camera. The +Y axis is up, and the Z axis points out off the camera. In order to render the world, everything in the scene must be transformed to camera coordinates.
 Local (or object) coordinate system.
Each object in the scene is defined in its own local coordinate system. By using a local coordinate system you can create many copies of the object, in different positions and orientations.
Matrix arithmetic
A 3x3 matrix can be used to represent a scaling [S] (resize an object) or rotation [R] (rotate an object about the origin by an angle Θ).
A 3x1 matrix can be used to represent a translation [T] (moves an object).
A 4x4 matrix can be used to combine a scaling or rotation with a translation.
The meaning of values a00...a23 are explained in the figures below:
A 4x4 matrix can store a single transformation (= rotation, scaling or translation) or a sequence of transformations. The latter is called a composite transformation. The matrix of a composite transformation is obtained by multiplying the matrices of the individual transformations.
The order of multiplying the matrices matters. Composite transformations are built from left to right. The product [S][R][T] (in that order) is the matrix of the composite transformation that first scales, then rotates, then translates. The matrix produced by the product [S][R][T] is different from the matrix produced by the product [T][R][S].
Rotations around the XYZ axes are necessary in order to describe any orientation of a body in space. Rotations about each axis are often used to transform between different coordinate systems. By using multiple coordinate systems, graphics algorithms are made easier to understand and to implement. In the figure below the two coordinate systems represent point P (in 2D space) in different ways.
The three rotation matrices are given below:
Rotation t_{x} around the Xaxis:



= 

1 
0 
0 
0 
cos(t_{x}) 
sin(t_{x}) 
0 
sin(t_{x}) 
cos(t_{x}) 





Rotation t_{y} around the Yaxis:



= 

cos(t_{y}) 
0 
sin(t_{y}) 
0 
1 
0 
sin(t_{y}) 
0 
cos(t_{y}) 





Rotation t_{z} around the Zaxis:



= 

cos(t_{z}) 
sin(t_{z}) 
0 
sin(t_{z}) 
cos(t_{z}) 
0 
0 
0 
1 





In games development, the particular order of rotations is to rotate about the Yaxis first, then the Xaxis, then the Zaxis:



= R_{z}(t) R_{x}(t) R_{y}(t) 



R_{z}(t) R_{x}(t) R_{y}(t) combined in a single matrix is:

cos(t_{z}) cos(t_{y}) + sin(t_{z}) sin(t_{x}) sin(t_{y}) 
sin(t_{z}) cos(t_{x}) 
cos(t_{z}) sin(t_{y}) + sin(t_{z}) sin(t_{x}) cos(t_{y}) 
sin(t_{z}) cos(t_{y}) + cos(t_{z}) sin(t_{x}) sin(t_{y}) 
cos (t_{z}) cos(t_{x}) 
sin(t_{z}) sin(t_{y}) + cos(t_{z}) sin(t_{x}) cos(t_{y}) 
cos(t_{x}) sin(t_{y}) 
sin(t_{x}) 
cos(t_{x}) cos(t_{y}) 


Rotation and translation about or in a particular axis are also indicated by a name:
 Pitch :Rotation about Xaxis
 Yaw :Rotation about Yaxis
 Roll :Rotation about Zaxis
 Strafe :Translation in Xaxis
 Fly :Translation in Yaxis
 Move :Translation in Zaxis
