Pro OpenGL ES for iOS

(singke) #1

208 CHAPTER 7: Well-Rendered Miscellany^


Figure 7-1. On the left, just Hedly is spinning. Both Hedly and his window are now spinning counterclockwise in
the middle. And on the right, the frame is spinning end over end.

Sun Buffer Objects


There are a lot of fun and bizarre things you can do with this equivalent to having 3D
superpowers. For example, you could simulate some animations on a little model of a
TV set. You could show multiple views of the same data in a reflection of a puddle on
the ground or the rearview mirror in a car. Better yet, put one OpenGL frame animating a
scene on the sun in our solar-system simulator. It’s not particularly realistic, but it’s
pretty cool.
Much of this is going to be left to the student this time around. I used Chapter 5’s final
projects for starters. You’ll need to add the FBController object and initialize it in a
different drawInRect() method taken from the previous exercise. The latter is in addition
to the execute() method used in the solar system. I’ll give you drawInRect(), as shown
in Listing 7-4, and leave the rest up to you.
Listing 7-4. Changes needed to drawInRect()


  • (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
    {
    static const GLfloat squareVertices[] = //1
    {
    -0.15f, -0.5, 0.0,
    -0.15f, 0.5, 0.0,
    0.15f, -0.5, 0.0,
    0.15f, 0.5, 0.0
    };

Free download pdf