Pro OpenGL ES for iOS

(singke) #1

CHAPTER 3: Building a 3D World (^81)
„ The first and last stacks contain the two poles, in which case they are
more of a triangle fan, as opposed to a strip, but we treat them as
strips to simplify the code.
„ Make sure that the end of each strip connects with the beginning to
form a contiguous set of triangles.
So, let’s break this down:
„ The initialization routine uses the notion of stacks and slices to define
the resolution of the sphere. Having more slices and stacks means a
much smoother sphere but uses much more memory along with
additional processing time. Think of a slice as similar to an apple
wedge, representing a piece of the sphere from bottom to top. A stack
is a slice that is lateral, defining sections of latitude. See Figure 3-16.
The radius parameter is a form of scale. You could opt to normalize all
your objects and use glScalef(), but that does add extra CPU
overhead, so in this case radius is used as a form of prescaling. And
squash is used to create a flattened sphere, necessary for Jupiter and
Saturn. Both have very high rates of revolution. (Jupiter’s day is only
about 10 hours, while its diameter is more than 10 times the Earth’s.)
As a result, its polar diameter is about 93 percent of the equatorial
diameter. And Saturn is even more flattened, with the polar diameter
only 90 percent of the equatorial.
„ Because we want something interesting to look at until we get to the
cool texture stuff in Chapter 5, let’s vary the colors from top to bottom.
The top is blue, and the bottom is red. The colorIncrement is merely
the color delta from stack to stack. Red starts at 255, and blue starts
at 0, using unsigned chars.
Figure 3-16. Stacks go up and down, slices go round and round, and faces are subdivided into triangle
strips.

Free download pdf