如何使用传感器数据影响 SceneKit 中的对象?
How can I use sensor data to affect the object in SceneKit?
我正在使用 SceneKit
在 iOS 平台上实施一个 AR
应用程序。我想让我的对象旋转然后移动旋转。对于移动旋转端,我发现在 CMAttitude
class 下有一个名为 quaternion 的参数,但我不确定如何使用此参数来旋转我在场景中加载的对象。有什么想法吗?
我尝试过使用 Core Motion,但我所做的是旋转 scnCamera
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 应用程序进行了尝试。
我正在使用 SceneKit
在 iOS 平台上实施一个 AR
应用程序。我想让我的对象旋转然后移动旋转。对于移动旋转端,我发现在 CMAttitude
class 下有一个名为 quaternion 的参数,但我不确定如何使用此参数来旋转我在场景中加载的对象。有什么想法吗?
我尝试过使用 Core Motion,但我所做的是旋转 scnCamera
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 应用程序进行了尝试。