How to calculate rotation angle using Android Sensors?

不羁岁月 提交于 2019-12-13 15:07:34

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!