Game Development Reference
In-Depth Information
10. Now we will take it to the next level by adding a code to rotate a cube. Now we
will animate movement in a view, such as rotation. Add the following instance
variable to the ViewController class in the interface part:
float rotation;
11. Next, add the following method to the class:
- (void) update {
NSTimeInterval timeInterval =
self.timeSinceLastUpdate;
float rotationSpeed = 15 * timeInterval;
rotation += rotationSpeed;
GLKMatrix4 modelViewMatrix =
GLKMatrix4MakeTranslation(0.0f, 0.0f, -6.0f);
modelViewMatrix = GLKMatrix4RotateX(modelViewMatrix,
GLKMathDegreesToRadians(45));
modelViewMatrix = GLKMatrix4RotateY(modelViewMatrix,
GLKMathDegreesToRadians(rotation));
_squareEffect.transform.modelviewMatrix =
modelViewMatrix;
}
12. Now, the update function should look something similar to the following screen-
shot:
13. Now compile and run the application. You will find your cube rotating at the
angle we have specified, as shown in the following screenshot:
Search WWH ::




Custom Search