Objects get drawn in their own ‘local’ coordinate system

World window gets scaled to viewport, so we adjust them to have the same aspect ratio, using the reshape() method.

# Transformation Matrices

We always load the identity matrix first; that way we don’t have random transformations leftover. This can be changed if you’re drawing subchildren as in a scene graph.

## Two Matrices

- Model View Matrix
- Most of these transforms (done on an object to draw it) will be done on this matrix

- Projection Matrix
- Changing the viewing shape space thing - done mostly on reshapes

# Transformations

The transformation matrices for 2D and 3D are very similar - just an extra column in the same format.

## Scale

Happens per axis. E.g. 0.2, 1, 0.5 is scaling it 3 times, each for an axis. This is easy to mess up if not done consistently in all of them (see shear further down).

In 2D the z value should be 1 - we don’t want to change it.

Negative numbers flip the value for that axis - it is a simple multiplication.

Vector scaling works the same.

## Rotate

Happens around an axis. It’s best to separate these into separate steps if doing multiple rotations.

Rotation around the z axis has the following matrix (for 2D);

For 3D rotation we have 3 axes to potentially rotate around, and hence have to combine cos and sin differently for each axis:

Vector rotation works the same way.

## Translate

The only one that results in a change in the origin. Shifts its position along each axis by the value given per axis.

Translation to a new origin (theta) has the following matrix (for 2D):

Translating a vector has no effect, as the 0 results in the new theta being meaningless.

## Shear

Shear is bad - it happens when scale is not uniform (e.g. 0.4, 2 not 2,2) and then rotation happens.

# Order

Each transformation modifies the coordinate systems - hence the order of the transformations affects the end result.

translate then rotate != rotate then translate

translate then scale != scale then rotate

rotate then scale != scale then rotate

To make a transformation matrix we start with identity and multiply on each change, in order.

In OpenGL if we apply glRotated etc this magically happens for us, so that all we need do is apply the correct transformations and then draw in the local coords.