I have the following code in my viewDidLoad, which is intended to rotate a SCNScene node "statue" based on the orientation of the device.
When I run the app on device, the statue's initial euler angles appear to be set by the device orientation, but moving the device doesn't update the euler angles of the node at all, and the node is completely stationary.
Any idea why the startDeviceMotionUpdates isn't calling the updateStatueOrientation function continuously?
// create a new scene
let scene = SCNScene(named: "art.scnassets/bathroom.scn")!
//attach statue node to code
let statue = scene.rootNode.childNode(withName: "statue", recursively: true)!
let motionManager = CMMotionManager()
motionManager.showsDeviceMovementDisplay = true
motionManager.deviceMotionUpdateInterval = 1.0 / 60.0
if motionManager.isDeviceMotionAvailable {
print("Motion active")
motionManager.startDeviceMotionUpdates(to: OperationQueue(), withHandler: { (motion: CMDeviceMotion?, err: Error?) in
updateStatueOrientation(m:motion!)
})
}
func updateStatueOrientation(m:CMDeviceMotion) {
statue.eulerAngles.z = Float(m.attitude.yaw - Double.pi)
statue.eulerAngles.y = Float(m.attitude.pitch)
statue.eulerAngles.z = Float(m.attitude.roll)
print("\(m.attitude.yaw) \(m.attitude.pitch) \(m.attitude.roll)")
}