呵呵,难得能遇到我可以解决的问题.我刚刚做好的程序用到这个.我来说明下吧
XXXAppDelegate.m 中
- (void)applicationDidFinishLaunching:(UIApplication *)application {
glView.animationInterval = 1.0 / 60.0;
[glView startAnimation];
//Configure and start accelerometer
//这里是启动重力感应,不加就没反映
[[UIAccelerometer sharedAccelerometer] setUpdateInterval:(1.0 / kAccelerometerFrequency)];
[[UIAccelerometer sharedAccelerometer] setDelegate:self];
}
#define kFilteringFactor 0.1
// Implement this method to get the lastest data from the accelerometer
- (void)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration {
//Use a basic low-pass filter to only keep the gravity in the accelerometer values
_accelerometer[0] = acceleration.x * kFilteringFactor + _accelerometer[0] * (1.0 - kFilteringFactor);
_accelerometer[1] = acceleration.y * kFilteringFactor + _accelerometer[1] * (1.0 - kFilteringFactor);
_accelerometer[2] = acceleration.z * kFilteringFactor + _accelerometer[2] * (1.0 - kFilteringFactor);
}
把_accelerometer数组传出来到程序中使用,[0]是X方向,[1]是Y方向,[2]是Z方向(没试过)