Super 2d Transformations
Super 2d Transformations
Super 2d Transformations
Transformations in 2 Dimensions
Vector and matrix operations are used to transform the images represented by
vectors. Any image can be considered to be made up of points (think of the pixels on a
monitor screen), and every one of these points has a position vector. For purposes of
demonstration, we can confine ourselves to the vertices of a figure- the corner points.
Consider the shape delineated by the points with position vectors , , , and
1. Translation entails moving all points in a figure by the same amount in a straight
line. This just means that we add the same number of units to each component of each
position vector making up the figure. For instance, to move the house down five units
and left 6 units, add the vector To each position vector of the house.
1
Visually;
The vector can be considered as a force that pushes the house down and left. The
operation of vector addition therefore amounts to simple movement in a plane. The
original computer games (Pong, Space Invaders) relied on very little more than this,
with the same shapes moving around on a flat background, and no changes of
perspective.
2
then apply the translation .
2. Reflection
Any line can be drawn across the plane, and the figure reflected in it, but reflection
across the axes is particularly important.
The y-coordinate of any vector we multiply by this has its sign flipped, while the x
coordinate is unchanged. For our house;
And visually:
3
Games like Pacman, Donkey Kong and the earliest Mario Brothers got by mostly on
translation and reflection.
3. Scaling (Stretching)
4
(All these results are the same as if we’d just multiplied the vectors by the scalar 2,
but the matrices have room for additional information and operations in them. We’ll
come to that.)
The matrix for a differential stretching by a factor of 3 in, say, the x direction only is;
5
Much of the Battleground game’s 3D effect was achieved by allowing tanks to change
size depending on their virtual proximity. Apart from this, not much more than
translation and reflection was used.
4. Rotation
Rotation consists of taking a point in the plane and turning the whole plane around
that point. The origin Is the most convenient point for demonstration. As we might
expect, since the rotation must go through a particular angle, the entries in the
transformation matrix are trigonometric.
6
Applying the same matrix to the other points,
7
Exercise 4. Rotate the runic P by 120 anticlockwise around the origin.
5. Shearing or deformation
The real use of shearing (or deformation) comes with 3D, but the 2D case illustrates
the principle. The transformation changes the angles of the figure while stretching it
in a given direction.
8
Similarly, the matrix for a shear by a factor of 2 parallel to the x-axis is