CHAPTER 10: OpenGL ES 2, Shaders, and... (^337)
m_Eyeposition.x=0.0;
m_Eyeposition.y=0.0;
m_Eyeposition.z=5.0;
m_Earth=[[Planet alloc] init:planetSize slices:planetSize //4
radius:.5f squash:1.0f
textureFile:@"earth_light.png"];
[m_Earth setPositionX:0.0 Y:0.0 Z:-3.0];
}
Bet you want to know what’s going on here?
The six-sided cube map is specified by creating an array of the six
images in lines 1ff.
Line 2 generates the GLKTextureInfo object and uses its cube map
support to fetch the six needed files.
The new effects object is allocated in line 3. After that, the lighting,
materials, and position info are filled in, not at all unlike good old’
OpenGL ES 1.
And finally, the earth is generated just like before, in line 4.
Now we need the update() and drawInRect() methods, as shown in Listing 10-18.
Listing 10-18. Updating the Effect
- (void)update
{
GLfloat scale=2.0;
float aspect = fabsf(self.view.bounds.size.width / self.view.bounds.size.height);//1
GLKMatrix4 projectionMatrix =
GLKMatrix4MakePerspective(GLKMathDegreesToRadians(65.0f), aspect, 0.1f, 100.0f);
self.effect.transform.projectionMatrix = projectionMatrix;
GLKMatrix4 baseModelViewMatrix = GLKMatrix4Identity;
GLKMatrix4 modelViewMatrix = GLKMatrix4Identity;
baseModelViewMatrix = GLKMatrix4Scale(baseModelViewMatrix,scale,scale,scale); //2
baseModelViewMatrix = GLKMatrix4Rotate(baseModelViewMatrix, _rotation, 0.0, 0.5,
0.0f);
modelViewMatrix = GLKMatrix4MakeTranslation(0.0, 0.0, -3.0);
modelViewMatrix = GLKMatrix4Multiply(modelViewMatrix, baseModelViewMatrix);
self.effect.transform.modelviewMatrix = modelViewMatrix;
self.effect.matrix=GLKMatrix3Identity; //3
_rotation+=0.03;
}