Matrix and Matrix Editor Tutoral

This is supposed to be a brief tutorial to introduce you to basic 3D
transformation matrices and the matrix stack editor in the newer (>=1.5)
versions of my modification to jonwil's RCT3 importer.

Contents

In this section I'll give a short introduction on the terms you'll need to
understand 3D matrix transformations. I'll start with the mathematical
definition and then try to explain in easy words what it means and how it
applies to 3D objects and their manipulation.

- Coordinate System
- A system for specifying points using coordinates measured in some
specified way. The simplest coordinate system consists of coordinate
axes oriented perpendicularly to each other, known as Cartesian
coordinates. Depending on the type of problem under consideration,
coordinate systems possessing special properties may allow particularly
simple solution.

Weisstein, Eric W. "Coordinate System." From*MathWorld*--A Wolfram Web Resource.

What needs further explanation are the terms

Left-handed coordinate system | Right-handed coordinate system |

Why do we need to discuss this? Many modelers (eg Blender) use a right-handed z-up coordinate system. This is the mathematical standart. It probably originates from 2D drawing. If you plot on a paper you use a 2D coordinate system where usually the x-axis points to the right and the y-axis points to the top of the sheet. If you now envision 3D space to "pop-out" of the paper along a z-axis you arrive at a right-handed, z-up system.

In 3D games, things are different. First, envision the 2D drawing on your screen. To switch to 3D, treat your screen as a window. Now the z-axis streches out into the "depth" of the screen. Jiggle your fingers, and you'll see that this constitutes a left-handed, y-up coordinate system, which is the standart in 3D gaming. RCT3 uses such a system.

This is the reason I added the fixup to the importer. If you model in a right-handed z-up system and import into RCT3, your model will end up lying on the side, being burried half in the earth and mirrored.

(Note: MilkShape uses a right-handed, y-up coordinate system. Don't ask me why.)

- Vertex (pl. vertices)
- A vertex is a special point of a mathematical object, and is usually
a location where two or more lines or edges meet. Vertices are most
commonly encountered in angles, polygons, polyhedra, and graphs. Graph
vertices are also known as nodes.

Weisstein, Eric W. "Vertex." From*MathWorld*--A Wolfram Web Resource. http://mathworld.wolfram.com/Vertex.html

To get a full 3D object, vertices are connected by edges that form

I will not discuss edges and faces further because they are not really relevant for 3D transformation matrices.

- Vector (pl. vectors)
- A vector is formally defined as an element of a vector space. In the
commonly encountered vector space R
^{n}(i.e., Euclidean*n*-space), a vector is given by*n*coordinates and can be specified as (A_{1}, A_{2}, ..., A_{n}). Vectors are sometimes referred to by the number of coordinates they have, so a 2-dimensional vector (x_{1},x_{2}) is often called a two-vector, an*n*-dimensional vector is often called an*n*-vector, and so on.

Weisstein, Eric W. "Vector." From*MathWorld*--A Wolfram Web Resource. http://mathworld.wolfram.com/Vector.html

I'll stop here so I don't confuse you :-) For our purpose, you can safley assume that a vector and a vertex are the same. If you want to be more precise, imagine the vector to be the arrow that points from the origin to the vertex.

- Matrix (pl. matrices)
- A matrix is a concise and useful way of uniquely representing and
working with linear transformations. In particular, for every linear
transformation, there exists exactly one corresponding matrix, and
every matrix corresponds to a unique linear transformation. The matrix,
and its close relative the determinant, are extremely important
concepts in linear algebra, and were first formulated by Sylvester and
Cayley.

Weisstein, Eric W. "Matrix." From*MathWorld*--A Wolfram Web Resource. http://mathworld.wolfram.com/Matrix.html

To transform a vertex (or vector in this case) it needs to be multiplied with the matrix. The exact procedure is beyond this brief introduction, but what you should know is, that it's mathematically impossible to multiply a 3D vector with a 4D matrix. To apply a 4D matrix we need a small trick. We just make the vector 4D by adding a fourth coordinate which we set to 1 (That's actually what makes the translation matrices work).

So why are matrices so convenient for 3D transformations? The reason is that you can merge several matrices into one, that in one step does all the transformations of the ones you merged. The mathematical operation behind this is called a

All the transformation matrices I'll explain now work with the origin as
center of operation. This doesn't matter for translation matrices, but is
important for rotation and scaling matrices (see there).

Translation

| 1.0 0.0 0.0 0.0 |
| 0.0 1.0 0.0 0.0 | | 0.0 0.0 1.0 0.0 | | x y z 1.0 | |

Moves your object by

Rotation

Around X-Axis | Around Y-Axis | Around Z-Axis |

| 1.0 0.0 0.0 0.0 |
| 0.0 cos(a) -sin(a) 0.0 | | 0.0 sin(a) cos(a) 0.0 | | 0.0 0.0 0.0 1.0 | |
| cos(a) 0.0 sin(a) 0.0 |
| 0.0 1.0 0.0 0.0 | | -sin(a) 0.0 cos(a) 0.0 | | 0.0 0.0 0.0 1.0 | |
| cos(a) -sin(a) 0.0 0.0 |
| sin(a) cos(a) 0.0 0.0 | | 0.0 0.0 1.0 0.0 | | 0.0 0.0 0.0 1.0 | |

Weisstein, Eric W. "Rotation Matrix." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/RotationMatrix.html |

Rotates your object by

Scale

| Sx 0.0 0.0 0.0 |
| 0.0 Sy 0.0 0.0 | | 0.0 0.0 Sz 0.0 | | 0.0 0.0 0.0 1.0 | |

Scales your object by