问题
I am doing an Opengl appln in which i have to rotate the camera, if the android device is rotated/tilted along Z axis.
I tried the SensorManager.getOrientation(R, orientVals);
using the magnetic and accelerometer sensors. But the values are very much fluctuating.
Gyroscope is also available in my device.
Since I am animating (rotate) the camera, I need a smooth rotation values
Please guide me in this regard.
回答1:
See How do you calculate the rate of rotation using the accelerometer values in Android for a particular axis on how to read Android's software-derived sensors that combine the data from the accelerometers, magnetometers, and (if available) gyroscopes.
To smooth values, use a low-pass filter or (better but more complicated) a Kalman filter. I suspect that Android's software-derived sensors such as the "rotation sensor" already use a Kalman filter to combine data from the different sensors. (One could search the source code...)
来源:https://stackoverflow.com/questions/8488911/how-to-calculate-rotation-angle-using-android-sensors