2008-09-27 67 views

回答

36

From the idevkit.com forums:

#define kFilteringFactor 0.1 
static UIAccelerationValue rollingX=0, rollingY=0, rollingZ=0; 


- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration { 

    // Calculate low pass values 

    rollingX = (acceleration.x * kFilteringFactor) + (rollingX * (1.0 - kFilteringFactor)); 
    rollingY = (acceleration.y * kFilteringFactor) + (rollingY * (1.0 - kFilteringFactor)); 
    rollingZ = (acceleration.z * kFilteringFactor) + (rollingZ * (1.0 - kFilteringFactor)); 

    // Subtract the low-pass value from the current value to get a simplified high-pass filter 

    float accelX = acceleration.x - rollingX; 
    float accelY = acceleration.y - rollingY; 
    float accelZ = acceleration.z - rollingZ; 

    // Use the acceleration data. 

} 
+0

謝謝!我知道我已經看到它在某處 – 2008-09-27 05:03:50