Pro OpenGL ES for iOS

(singke) #1

CHAPTER 8: Putting It All Together (^249)
jump to 20.1°, you merely add a teeny-tiny more of that arc to your current quaternion
instead of having to go through the tedious process of generating the three matrices
each time and multiplying them together. This process is called slerping, where slerp
stands for spherical linear interpolation. Because an axis/angle pair does not rely on a
cumulative summation of all previous ones like when using matrices but on an
instantaneous value, there is no error buildup as a result of the former.
Figure 8-2. An intermediate quaternion; Q1.5 on a sphere can be interpolated from two others, Q1 and Q2.
Slerp is used to provide those smooth animations of a viewpoint’s ‘‘camera’’ when going
from one point to another. It can be part of a flight simulator, a space simulator, or the
view from a chase car for a racing game. And naturally they are used in real flight
guidance systems as well.
So, now with that bit of background, we’re going to use quaternions to help move the
earth around.
Moving Things in 3D
Since we are not animating the earth currently, there needs to be a way to move it
around so we can investigate it from all ends. With that in mind, since the earth is our
target of interest, we’ll set up a situation in which the eye point will effectively hover over
the earth directed by pinch and drag gestures.
The first step is to add gesture recognizers, which have been available on the iPad from
day one but available on the other devices only since iOS 4.
Note For a “real” application, you might consider whether the convenience of gesture
recognizers is worth cutting off the first-generation iOS users who are limited to iOS 3.x.
If you are new enough to iOS programming, you might not have come across gesture
recognizers. In brief, they handle the tedium of determining what kind of touch gesture
the user has made, something the developer had to do early on. It could get plenty
messy, especially when taking care of rotation gestures. Swipe, tap, pinch, and pan

Free download pdf