**See Also:**Making a Game Engine: Core Design Principles Moving objects around in a scene is not hard to do. You simply draw objects at different locations each frame. Adding rotation, and resizing on top of that makes the code a little trickier but still not hard to manage. But then start trying to move objects relative to another such as putting a sword in a character's hand and things can get really tricky. The sword should stay in the character's hand regardless of what direction they rotate or where they move. This is where using matrices to represent these transformations is extremely valuable.

## Coordinate Systems

In order for a coordinate to have any meaning there needs to be a point of reference to base that coordinate off of. Imagine you have a dot on a piece of paper. The dot does not have a coordinate unless you come up with a way to measure its location. One way would be to determine the distance the point is from the left side of the page and its distance from the bottom. These two measurements give the coordinate meaning since it has a point of reference, the bottom left corner of the page. The point of reference is known as a basis and any point measured relative to the same basis are said to be in the same coordinate system. If a worm were on a ball you could devise a way to measure the location of the worm on the ball. This coordinate would be the worm's location in the ball's coordinate space.## Basic Transformations

**Translation**A translation simply changes an object's location. The matrix used to represent this is pretty simple too. [attachment=19757:TranslationMatrix.png] T[sub]x[/sub] and T[sub]y[/sub] is the number of units to move in the x and y directions respectively.

**Rotation**Rotates points around the origin. [attachment=19758:RotationMatrix.png] The above matrix will rotate counter clockwise by ? radians.

**Scaling**Scaling an object changes its size. Scalar values in the range (0, 1) make objects smaller. A scale of 1 keeps it the same size, a scale greater than 1 makes it bigger. Really all the scale is doing is taking the current size and multiplying by the scale value. [attachment=19762:ScaleMatrix.png] Scales along the x and y directions by S[sub]x[/sub] and S[sub]y[/sub] respectively. When S[sub]x[/sub] = S[sub]y[/sub] the size will change uniformly. If you only modify a single value then the object will stretch meaning you can make an object wider by setting S[sub]x[/sub] to a value greater than 1 and keeping y the same. You can even make a value negative which will flip the object.

## Using Matrices as Transforms

**Transforming Points**Now that we have a few different transformation matrices we need a way to transform points using them. To do this you simply treat the point as a 1x3 matrix padding the extra slots with a 1 and multiplying it with the transform matrix. [attachment=19883:TransformPoint.png] The result of that multiplication is a another 1x3 matrix. Just taking the top two elements of the resulting matrix gives a new x, y pair of the point in the new coordinate system.

**Transforming Directions**Transforming a direction is slightly different than transforming a point. Take a look at the example below.

**Concatenating transforms**The three basic tranformations listed above aren't that useful on their own. To make things interesting we want to be able to join them together allowing objects to be translated, rotated, and scaled simultaneously. To do this we simply multiply the matrices together. [attachment=19764:MatrixConcat.png] The resulting matrix,

*M*, is a combination of scaling an object, rotating it, then translating it. Keep in mind that the order of

*T*,

*R*and

*S*does matter. Since

*S*is the right-most matrix its transformation will be applied first when transforming a point followed by

*R*, followed by

*T*. To see this grab some object nearby, such as a pencil, and hold it so it is pointing to the right. Now imagine that the pencil is first scaled by half in the x direction making the pencil shorter but not changing its thickness. Then the pencil is rotated 90 upward. The result is a short pencil with the same width pointing upward. Now switch the transformation order. First rotate it upward then scale. The resulting trasnform is a pencil of the same length but different width. So pay attention to the transform order.