Pro OpenGL ES for iOS

(singke) #1

CHAPTER 8: Putting It All Together (^269)
gluGetScreenLocation(planetPos.x,-planetPos.y,planetPos.z,sx,sy,sz); //13
glPopMatrix();
angle+=.5;
}
In addition to the previous, add the following to the header:
#define STANDARD_FOV 30.0 //in degrees
OK, now for the chalk talk:
„ You’ll notice that two identical glTranslatef() calls are made. The
first one in line 1 sets things up for line 2 results. But we need to pop it
off the stack when our custom sun image is rendered in line 4. It needs
to be called again in line 6, when the earth is drawn to the screen.
„ In line 2 it looks like we’re rendering the sun. But not really. This is to
extract the location on the main screen that the sun would actually
draw to. The last parameter, render, will have the routine just return
the screen location and expected radius but not actually draw the sun.
„ Line 3 decides whether we should draw the new sun if a lens flare
object has been created and if the sun is likely to be visible based on
its z-coordinate. If z is negative, then it is behind us, so we can skip it
altogether.
„ Lines 4f figure out how large to render the new texture. Naturally we
can’t use just the radius, because the texture is considerably larger to
handle the main image plus the glow. The various values used are
rather arbitrary in calculating the sunWidth, but they balance out
nicely.
„ The call to renderTextureInRect() in line 5 makes sure that the sun’s
rect is centered by subtracting half of sunWidth from the screen x and
screen y locations.
As a side effect of the way this is drawn, depth cueing doesn’t work
very well, so z-buffering cannot be used. By drawing it as the first
item, we are assured that the closer objects will properly write over
any part of the image as needed.
„ Line 6 is a repeat of the first line, but this time used to render the earth
in line 7. Got that? Note that we get the earth’s screen x and y values,
along with the radius as we did for the sun earlier.

Free download pdf