Pro OpenGL ES for iOS

(singke) #1

34 CHAPTER 2: All That Math Jazz^


2D Transformations

Without knowing it, you probably have used 2D transformations already in the form of
simple translations. If you create a UIImageView object and want to move it based on
where the user is touching the screen, you might grab its frame and update the x and y
values of the origin.

Translations


You have two ways to visualize this process. The first is having the object itself move
relative to a common origin. This is called a geometric transformation. The second is
having the world origin move while the object stays stationary. This is called a
coordinate transformation. In OpenGL ES, both descriptions are commonly used
together.
A translational operation can be expressed this way:

x′=x+Tx y′=y+T


The original coordinates are x and y, while the translations, T, will move the points to
a new location. Simple enough. As you can tell, translations are naturally going to be
very fast.

Note Lowercase letters, such as xyz, are the coordinates, while uppercase letters, such as
XYZ, reference the axis.

Rotations


Now let’s take a look at rotations. In this case, we’ll rotate around the world origin at first
to keep things simple. (See Figure 2-2.)
Free download pdf