CHAPTER 7: Well-Rendered Miscellany (^231)
m_SpinX=0.0;
m_SpinY=0.0;
m_SpinZ=0.0;
m_WorldZ=-6.0; //2
m_WorldY=-1.0;
m_LightRadius=2.5; //3
[(EAGLView *)self.view setContext:context];
}
In lines 1f, the world rotations are set up; 90º will have you looking
straight down in the scene, while 0º will have you looking straight on
the side.
The world locations for the scene are established in lines 2f.
Decreasing z will move the scene further away; increasing z moves it
closer. Decreasing y will move it down on the screen, and increasing it
will move it up.
m_LightRadius in line 3 means the radius of the circle that the light
moves above the scene.
The drawInRect() method is covered in Listing 7-12. The most immediate change you’ll
notice is that the geometry and color arrays are nowhere to be found. Actually, I have
now moved them up to the top of the file as globally defined data. That made it a little
easier to break the rendering stuff into smaller bits. Interestingly enough, a lot of
OpenGL geometric descriptions are kept in .h f i l e s -----really, really, really big .h files.
Apple actually recommends this approach for some tasks and uses it in its OpenGL
example that draws the infamous teapot. That file is more than 3,000 lines long.
Listing 7-12. The drawInRect() method for projected shadows
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{
int lightsOnFlagTrigger=300; //1
bool lightsOnFlag=true;
static int frameNumber=0;
GLfloat minY=2.0;
static GLfloat transY=0.0;
m_TransY=(GLfloat)(sinf(transY)/2.0)+minY; //2
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.0, 0.0, 0.0, 1.0);
glEnable(GL_DEPTH_TEST);
[self updateLightPosition]; //3