我正在使用陀螺开发AR应用程序.我使用了一个苹果代码示例pARk.它使用旋转矩阵来计算坐标的位置并且它确实很好,但是现在我正在尝试实现"雷达",我需要在设备标题的功能中旋转它.我正在使用CLLocationManager标题,但它不正确.
问题是,如何使用CMAttitude获取设备的标题以准确反映我在屏幕中得到的内容?
我是新的旋转矩阵和那种东西.
这是用于计算AR坐标的代码的一部分.以态度更新cameraTransform:
CMDeviceMotion *d = motionManager.deviceMotion;
if (d != nil) {
CMRotationMatrix r = d.attitude.rotationMatrix;
transformFromCMRotationMatrix(cameraTransform, &r);
[self setNeedsDisplay];
}
Run Code Online (Sandbox Code Playgroud)
然后在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;
Run Code Online (Sandbox Code Playgroud)
我还用俯仰角旋转视图.运动更新使用北方开始:
[motionManager startDeviceMotionUpdatesUsingReferenceFrame:CMAttitudeReferenceFrameXTrueNorthZVertical];
Run Code Online (Sandbox Code Playgroud)
所以我认为必须有可能在任何位置(任何俯仰和偏航......)获得设备的"滚动"/标题,但我不知道如何.