我正在使用陀螺仪开发 AR 应用程序。我使用了一个苹果代码示例公园。它使用旋转矩阵来计算坐标的位置,它做得很好,但现在我正在尝试实现一个“雷达”,我需要根据设备航向来旋转它。我正在使用 CLLocationManager 标题,但它不正确。
问题是,如何使用 CMAttitude 获取设备的标题以准确反映我在屏幕上看到的内容?
我是旋转矩阵之类的新手。
这是用于计算 AR 坐标的代码的一部分。用姿态更新 cameraTransform:
CMDeviceMotion *d = motionManager.deviceMotion;
if (d != nil) {
CMRotationMatrix r = d.attitude.rotationMatrix;
transformFromCMRotationMatrix(cameraTransform, &r);
[self setNeedsDisplay];
}
然后在drawRect代码中:
mat4f_t projectionCameraTransform;
multiplyMatrixAndMatrix(projectionCameraTransform, projectionTransform, cameraTransform);
int i = 0;
for (PlaceOfInterest *poi in [placesOfInterest objectEnumerator]) {
vec4f_t v;
multiplyMatrixAndVector(v, projectionCameraTransform, placesOfInterestCoordinates[i]);
float x = (v[0] / v[3] + 1.0f) * 0.5f;
float y = (v[1] / v[3] + 1.0f) * 0.5f;
我还用俯仰角旋转视图。运动更新使用北开始:
[motionManager startDeviceMotionUpdatesUsingReferenceFrame:CMAttitudeReferenceFrameXTrueNorthZVertical];
所以我认为必须有可能让设备的“滚动”/航向处于任何位置(任何俯仰和偏航......),但我不知道如何。