I am creating a 360 video viewer using the iOS SceneKit framework .
I would like to use UIPanGestureRecognizer to control camera orientation.
SCNNode have several properties that we can use to indicate their rotation: rotation ( rotation matrix), orientation (a quaternion), eulerAngles (at each angle of the axis).
All I read says to avoid using Euler angles to avoid gimbal lock .
I would like to use quaternions for several reasons that I will not do here.
I am having trouble getting this to work correctly. Camera control is almost where I would like to, but something is wrong. It seems that the camera rotates around the Z axis, despite my attempts to influence only the X and Y axes.
I believe the problem is related to my quaternion multiplication logic. I have not done anything related to quaternion in years :( My migration handler is here:
func didPan(recognizer: UIPanGestureRecognizer) { switch recognizer.state { case .Began: self.previousPanTranslation = .zero case .Changed: guard let previous = self.previousPanTranslation else { assertionFailure("Attempt to unwrap previous pan translation failed.") return }
My open source code is here: https://github.com/alfiehanssen/360Player/
Check out the pan-gesture : https://github.com/alfiehanssen/360Player/tree/pan-gesture
If you pull the code down, I believe that you will have to run it on the device, not on the simulator.
I posted a video here demonstrating the error (please, excuse me for the low quality of the video file): https://vimeo.com/174346191
Thanks in advance for your help!