Using multiple accelerometer values at once can allow the user to manipulate the rotation of a 3D object in space. This is used to great effect in the Super Monkey Ball series of iOS games.
Please refer to the project RecipeCollection01 for full working code of this recipe. Please note that the IphoneCube
class code was omitted from this example as it is similar to the 3D cube code in Chapter 1, Graphics.
Execute the following code:
#import "IphoneCube.h" @implementation Ch2_AccelerometerRotation -(CCLayer*) runRecipe { //Enable the accelerometer and set its updateInterval self.isAccelerometerEnabled = YES; [[UIAccelerometer sharedAccelerometer] setUpdateInterval:(1.0 / 60)]; //Init our textured box iphoneCube = [[IphoneCube alloc] init]; iphoneCube.translation3D = [Vector3D x:0.0f y:0.0f z:-2.0f]; iphoneCube.rotation3DAxis = [Vector3D x:0.0f y:0.0f z:(PI/2 - 0.075f)]; [self addChild:iphoneCube z:3 tag...