In a robust game environment objects are constantly changing. They are moving around the screen (translation). They are moving closer and farther away giving the appearance of shrinking or growing (scaling). And they are changing their orientation (rotation). In this section, we will look at the transformations of translation and scaling and their interconnectedness through concatenation.

Most objects consist of a collection of polygons. Each polygon is described by its vertices. We can represent these vertices as vectors. So we can think of a transformation of an object as a transformation on the vertices or vectors that make up its polygons.

# Translation

To translate a point $P(x,y,z)$ and therefore its position vector $\vec{p}=<x,y,z>$ by $\Delta x$ in the *x* direction, $\Delta y$ in the *y* direction and $\Delta z$ in the *z* direction we have the option of using either a matrix addition or a matrix multiplication. For our later purposes of concatenation, the multiplication approach will be preferred.

Using matrix addition we have the following

Using matrix multiplication we have the following. Notice that this cannot be accomplished without the homogeneous coordinate. This is why we coded $w$ into our vector class.

(2)Regardless of whether we use the addition or multiplication approach, the result is the same. The advantage of using multiplication is that it becomes possible to combine multiple transformations into a single matrix multiplication.

Exercise

Move the point, $(-3,-8,5)$, 4 units in the positive x-direction, do not move at all in the y-direction, and move 2 units in the negative z-direction using first matrix addition and then matrix multiplication.

Exercise

Move the 2D object consisting of vertices , $(1,1,)$, $(4,1)$, $(4,6)$ , 5 units in the negative x-direction and 6 units in the negative y-direction using matrix multiplication.

# Scaling

To scale a vector $<x,y,z>$ by a factor of $S_x$ in the *x* direction, a factor of $S_y$ in the *y* direction and a factor of $S_z$ in the *z* direction we use the following matrix multiplication.

For a simple 2D example say we had a triangle with vertices (1,1), (2,1) and (2,2) and we wanted to scale by a factor of 2 in the *x* direction and a factor of 3 in the *y* direction.

The image below shows the result of our scaling.

Notice the possibly unintended consequence of moving the object as well as scaling it. This is because of the fact that the scaling is really stretching the points away from the axes. One way to ovoid this is to scale an object about its center.

Exercise

Scale the 2D object consisting of vertices , $(1,1,)$, $(4,1)$, $(4,6)$ , by a factor of 2 in the x-direction and a factor of $\frac{1}{2}$ in the y-direction using matrix multiplication.

# Scaling About a Center

If we scale an object whose center is at the origin, the scaled object will still have its center at the origin. This avoids the unintended movement that we saw previously. To accomplish this, we must first translate the object so that its center is at the origin. Then we will scale the object. Then we will translate its center back to its original location.

The following matrix multiplication shows the scaling of a vector by factors $S_x,S_y,S_z$ about the object's center $(x_c,y_c,z_c)$

(5)# Concatenation

Since each of our transformations in 3D is a multiplication by a $4\times4$ matrix, we can multiply those matrices together to obtain a single $4\times 4$ matrix that will achieve multiple transformations at once. This new matrix is refered to as a **concatenation**. If we multiply the three matirces used for scaling about a center we obtain the following concatenation.

So given an object's center and the directional scaling factors, we simply multiply each vector of the object by the concatenation below to obtain a scaling about its center.

(7)

Exercise

Scale the 2D object consisting of vertices , $(1,1,)$, $(4,1)$, $(4,6)$ , by a factor of 2 in the x-direction and a factor of $\frac{1}{2}$ in the y-direction about its center using matrix multiplication.

Exercise

Find the concatenation that would first double the size in the x and z-directions while reducing the size by 10% in the y-direction, and then move the object in the direction of $<10,-5,0>$

# Exercises

1) In which order are the following operations occurring on the object?

(8)2) What is the side effect of raw scaling and why does it occur?

3) How can you avoid the side effect of raw scaling?

4) Give the matrix that using matrix multiplication would translate an object in the direction $<5,-3,9>$

5) Give the matrix that would raw scale an object by a factor of 4 in the x-direction, a factor of -2 in the y-direction and 0.5 in the z-direction

6) Below are the vertices of an object in the xy-plane.

a) Come up with an estimate of its center

b) Give the concatenation that scales the object about its center by a factor of 10 in the x-direction and 0.25 in the y-direction.

c) Give the new vertices

7) Give the concatenation that would first translate an object in the direction $<1,-1,2>$ and then scale the object by a factor of 3 in the x-direction, 4 in the y-direction, and -1 in the z-direction.

8) Give the concatenation that would first scale an object by a factor of 3 in the x-direction, 4 in the y-direction, and -1 in the z-direction and then translate the object in the direction $<1,-1,2>$.