我正在使用SceneKit
在iOS平台中实现一个AR
应用程序。我想让我的对象旋转,然后移动旋转。对于移动旋转方面,我发现类下有一个名为四元数CMAttitude
参数,但我不确定如何使用此参数来旋转我在场景中加载的对象。有什么想法吗?
let motionManager = CMMotionManager()
motionManager.deviceMotionUpdateInterval = 1.0 / 60.0
if motionManager.isDeviceMotionAvailable {
motionManager.startDeviceMotionUpdates(to: OperationQueue.main, withHandler: { (devMotion, error) -> Void in
//change the left camera node euler angle in x, y, z axis
cameraNode.eulerAngles = SCNVector3(
-Float((devMotion?.attitude.roll)!) - Float(M_PI_2),
Float((motionManager.deviceMotion?.attitude.yaw)!),
-Float((motionManager.deviceMotion?.attitude.pitch)!)
)
})}
我在iPad中的Playground应用程序中尝试过这个。
我尝试使用Core Motion,但我所做的是旋转scnCamera