如何将设备加速转化为全局加速

How Convert Device Acceleration to Global Acceleration

我正在为 android 开发一个统一应用程序,它需要借助加速度计来测量设备运动。问题是这些值包含重力。有人说为了去除重力,我必须将加速度转换为全局加速度,然后才从 Z 轴去除重力,但我不知道该怎么做?有什么特殊的统一函数可以做到这一点吗?

谢谢

Unity 论坛上的这个帖子解决了问题:

https://forum.unity.com/threads/unity-and-the-accelerometer-vs-the-gyroscope-a-complete-guide.451496/

正如来自 Unity Technologies 的 "inkredibl" 所说:

In Unity Gyroscope.rotationRate is the real gyroscope data, all the other properties of that class use other sensors (when available) to come up with better estimations of real-world device movements. Gyroscope.gravity and Gyroscope.userAcceleration are related to accelerometer but with the help of other sensors they have gravity separated out from device acceleration to make it easier for developers to use (but this is again an estimation, they're not perfect, only close enough).

所以Gyroscope.userAcceleration就是这个问题的答案

Input.acceleration is accelerometer data and it's measured in multiples of g (Eearth's gravity), that's why it's magnitude is 1 when the device is not being moved. Try logging it when the device is thrown up in the air and it should be close to zero (that's because the device is in free-fall at that moment). Compass.rawVector is magnetometer data and again all the other properties of that class are derived using various sensors not just the magnetometer.