246 CHAPTER 8: Putting It All Together^
Using the ‘‘drawable’’ fields is recommended by Apple, although the more traditional
way, using the frame of the mainScreen, should still be valid if you are creating a display
to be the size of the screen.
Revisiting the Solar System
Go back to Chapter 5 and get the solar-system model that was used as the final project.
The Chapter 7 model was used as a surface for displaying dynamic textures on 3D
objects, but that won’t be used here in that way.
So, the first thing to tackle is resizing our models to make a slightly more realistic
presentation. As of right now, it looks like the earth is about a third the size of the sun
and only a few thousand miles (or furlongs if you care) away. Considering that it is a
pleasant fall day here in Northern California and the earth is anything but a burnt cinder,
I bet the model is wrong. Well, let’s make it right. This will be done in the initGeometry()
method in your solar-system controller. And while we’re at it, the type of m_Eyeposition
will be changed to upgrade it to a slightly more objectified object customized for 3D
operations. The new routine is in Listing 8-1. Make sure to add a texture for the sun’s
surface while you are at it; otherwise, nasty things might happen.
Listing 8-1. Resizing the objects for the solar system
-(void)initGeometry
{
//Let 1.0=1 million miles.
// The sun's radius=.4.
// The earth's radius=.04 (10x larger to make it easier to see).
m_Eyeposition.x=0;
m_Eyeposition.y=0;
m_Eyeposition.z=93.25;
m_Earth=[[Planet alloc] init:48 slices:48 radius:0.04
squash:1.0 textureFile:@"earth_light.png"];
[m_Earth setPositionX:0.0 Y:0.0 Z:93.0];
m_Sun=[[Planet alloc] init:48 slices:48 radius:0.4
squash:1.0 textureFile:@"sun_surface.png"];
}
m_Eyeposition is now defined as a new GLKVector3 object.
Note The new iOS5 vector classes are very well thought out, because they use unions to
support xyz values, rgb, stp (for texture coordinates), and the ever popular array format, float
v[3]. Similar conventions are used for the other container classes as well.