After reading through conversions between Euler angles and unit quaternions, I was able to write a function that converted my desired Euler xyz angles to a quaternion. This way, the snapshot function captures the rotation. Below is my method written in Swift to perform the conversion.
func angleConversion(x: Float, y: Float, z: Float, w: Float) -> (Float, Float, Float, Float) {
let c1 = cos( x / 2 )
let c2 = cos( y / 2 )
let c3 = cos( z / 2 )
let s1 = sin( x / 2 )
let s2 = sin( y / 2 )
let s3 = sin( z / 2 )
let xF = s1 * c2 * c3 + c1 * s2 * s3
let yF = c1 * s2 * c3 - s1 * c2 * s3
let zF = c1 * c2 * s3 + s1 * s2 * c3
let wF = c1 * c2 * c3 - s1 * s2 * s3
return (xF, yF, zF, wF)
}
Implementation
let (x, y, z, w) = angleConversion(x: 0, y: 1.1*Float(Double.pi), z: 0, w: 0)
sphereNode.localRotate(by: SCNQuaternion(x, y, z, w))
Topic:
Graphics & Games
SubTopic:
SceneKit
Tags: