在 iOS5 中,Compass 原始数据读取的更新频率CLHeading
急剧下降。这使得我的增强现实应用程序无法使用,因为它依赖于对原始指南针数据的接近实时读取。
因此,我现在正尝试切换到 CoreMotion。这提供了更频繁更新的磁力计数据:
cmManager = [[CMMotionManager alloc] init];
[cmManager startMagnetometerUpdates];
magneticField
然后我可以在游戏期间随时访问数据:
CMMagneticField magneticField = cmManager.magnetometerData.magneticField;
我遇到的问题如下: 中的数据与x/y/z 数据CMMagneticField
的单位不同。CLHeading
我想将CMMagneticField
x/y/z 数据转换为与 CLHeading / CLHeadingComponentValue 相同的单位——以便能够使用我现有的 AR 代码。
这里有一些读数:
7.3 / 17.64 / -39.58 CLHeadingComponentValue X/Y/Z
-103.12 / 88.51 / -20.05 CMMagneticField
-10.81 / -34.9 / -18.6 CLHeadingComponentValue X/Y/Z
-121.00 / 33.29 / 3.1 CMMagneticField
-20.8 / -38.0 / -4.0 CLHeadingComponentValue X/Y/Z
-132.9 / 32.2 / 14.4 CMMagneticField