Chapter 8
Putting It All Together
A single lifetime, even though entirely devoted to the sky, would not be
enough for the investigation of so vast a subject.
-----Seneca, Roman philosopher
Well, now we’ve made it all the way up to Chapter 8. This is when we can take what was
learned from the exercises up to this point and slap it together into a more complete
solar-system model. And afterward, I hope you will say, ‘‘Wow! That’s kinda cool!’’
This chapter will be very code heavy, because the model requires both a number of new
routines and modifications to existing projects. So, as with Chapter 7 I’ll be breaking
with the style of the previous chapters and will not present entire code files because of
their length or to avoid repetition; therefore, you are encouraged to fetch the full
projects, as well as some data files, from the Apress site to ensure that you have fully
functional examples. A few new tricks will also be tossed in for good measure such as
how to integrate the standard iPhone UIKit and the use of quaternions. Note that
although a lot of the following code is based on previous exercises, there are likely some
small tweaks needed to integrate it into the larger package, so unfortunately this won’t
simply be a cut-and-paste situation.
But What About a Retina Display?
Yes, I know, everything looks better on a Retina display, so let’s tell OpenGL how to
handle the higher resolution before we do anything else. Oh, wait. We don’t have to do
that anymore. Pre-iOS 5, it was necessary to tell the OpenGL view object how to size
itself using the setContentScaleFactor instance variable. It would be 1.0 for the old-
school displays, or 2.0 for Retina. Under the GLKit, that kind of housekeeping is no
longer needed. However, you will still need to grab the actual dimensions of the view
when it comes time to set the glViewPort() when setting the viewing frustum, as follows,
remembering that the view here is actually the GLKView subclassed from the UIView.
glViewport(0, 0, view.drawableWidth, view.drawableHeight);