使用Swift 3在IOS 10 coremotion中选择姿态参考系 [英] selecting attitude reference frame in IOS 10 coremotion using swift 3

查看:129
本文介绍了使用Swift 3在IOS 10 coremotion中选择姿态参考系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用CMMotionManager更新场景套件中相机视点的姿态.我可以使用默认引用来获得以下代码.

I am trying to use CMMotionManager to update the attitude of a camera viewpoint in scenekit. I am able to get the following code using the default reference to work.

manager.deviceMotionUpdateInterval = 0.01
manager.startDeviceMotionUpdates(to: motionQueue, withHandler:{ deviceManager, error in
                if (deviceManager?.attitude) != nil {
                    let rotation = deviceManager?.attitude.quaternion

                    OperationQueue.main.addOperation {
                        self.cameraNode.rotation = SCNVector4(rotation!.x,rotation!.y,rotation!.z,rotation!.w)
                    }
                }

        })

但是我无法使startDeviceMotionUpdates与选定的参考框架一起使用,如下所示:

I am however unable to get startDeviceMotionUpdates to work with a selected reference frame as shown below:

manager.deviceMotionUpdateInterval = 0.01
manager.startDeviceMotionUpdates(using: CMAttitudeReferenceFrameXMagneticNorthZVertical, to: motionQueue, withHandler:{ deviceManager, error in
            if (deviceManager?.attitude) != nil {
                let rotation = deviceManager?.attitude.quaternion

                OperationQueue.main.addOperation {
                    self.cameraNode.rotation = SCNVector4(rotation!.x,rotation!.y,rotation!.z,rotation!.w)
                }
            }

        })

我收到的错误是:

Use of unresolved identifier 'CMAttitudeReferenceFrameXMagneticNorthZVertical'

对于其他参考系,我也会收到类似的错误消息.任何人都可以对startDeviceMotionUpdates函数的"using:"参数的使用有所了解吗?我发现的所有示例都是针对较早版本的swift或Objective c的,因此很可能这是一个不了解Swift 3语法的问题.

I get similar error messages for other reference frames as well. Can anyone shed any light on the use of the "using:" parameter for the startDeviceMotionUpdates function? All the examples i have found are for older versions of swift or objective c so it is quite possible that it is simply an issue with not understanding Swift 3 syntax.

推荐答案

经过一些摆弄之后,我发现using参数需要新CMAttitudeReferenceFrame结构的成员.即应将其传递为:

After some additional fiddling i figured out that the using argument expects a member of the new CMAttitudeReferenceFrame struct. i.e. it should be passed as:

manager.deviceMotionUpdateInterval = 0.01
manager.startDeviceMotionUpdates(using: CMAttitudeReferenceFrame.xMagneticNorthZVertical
            ,to: motionQueue, withHandler:{
            deviceManager, error in
            if (deviceManager?.attitude) != nil {
                let rotation = deviceManager?.attitude.quaternion

                OperationQueue.main.addOperation {
                    self.cameraNode.rotation = SCNVector4(rotation!.x,rotation!.y,rotation!.z,rotation!.w)
                }
            }

        })

这是对较早版本的更改,该版本允许直接使用常量,例如"CMAttitudeReferenceFrameXMagneticNorthZVertical"

This is a change from earlier version that allowed the direct use of constants such as "CMAttitudeReferenceFrameXMagneticNorthZVertical"

这篇关于使用Swift 3在IOS 10 coremotion中选择姿态参考系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆