Pro OpenGL ES for iOS

(singke) #1

266 CHAPTER 8: Putting It All Together^


„ The multiplication is done via another GLUT helper routine at lines 2ff.
First the projection matrix and then the model matrix operate on our
object’s xyz coordinates. (Remember, the first transform in the list is
the last to be executed.) Note that the first call to
gluMultMatrixVector3f() passes the ‘‘in’’ array, followed by the ‘‘out,’’
while the second one passes the two arrays in reverse order. There’s
n o t h i n g c l e v e r h e r e -----the second instance reverses the use of the two
just to recycle the existing arrays.
„ In lines 3ff, the resulting values of the earlier calculations are
normalized and then mapped against the screen’s dimensions, giving
us the final values.
„ We’d likely never to have to call gluProject() directly; instead, the
caller is gluGetScreenLocation(), which merely gets the needed
matrices in lines 4ff, passes them on to gluProject(), and retrieves
the screen coordinates. Because of the inversion of the Y-axis that
OpenGL ES does, we need to uninvert it in line 5.
„ And one final tweak comes courtesy of the Retina display, in line 6.
The de facto screen dimensions on the iPhone are 320x480. What the
scale value is used for is to scale up any screen coordinates to handle
the higher resolution. Scale would be 1 on any pre-Retina devices,
while it would be 2 otherwise.
The execute() routine in the SolarSystemController must be modified quite a bit to
manage the calling and placement of the lens flare, while along with an executePlanet()
adds some new parameters to actually identify where the flare should be located on the
screen. Both are given in Listing 8-11.
Listing 8-11. The modified execute() and executePlanet() methods

-(void)execute
{
float earth_sx,earth_sy,earth_sz,earth_sr;
float sun_sx,sun_sy,sun_sz,sun_sr;
GLfloat paleYellow[]={1.0,1.0,0.3,1.0};
GLfloat white[]={1.0,1.0,1.0,1.0};
GLfloat cyan[]={0.0,1.0,1.0,1.0};
GLfloat black[]={0.0,0.0,0.0,0.0};
GLfloat sunPos[4]={0.0,0.0,0.0,1.0};

[self setClipping];

glMatrixMode(GL_MODELVIEW);
glShadeModel(GL_SMOOTH);
glEnable(GL_LIGHTING);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Free download pdf