I need to convert the motion from an accelerometer into the appropriate values in order to rotate a SceneKit Object. My code to convert the raw x,y,z values into Radians is:
let theta : Float = atan2(x, sqrtf(powf(y, 2)+powf(z, 2)))
let psi : Float = atan2(y, sqrtf(powf(x, 2)+powf(z, 2)))
let phi : Float = atan2(sqrtf(powf(x, 2)+powf(y, 2)), z)
I'm struggling to convert this into a full 360 degree angle to rotate the object.
Any help?
In SceneKit you can use x,y,z euler angles directly:
let object:SCNNode = ...
object.eulerAngles = SCNVector3(x: CGFloat(x), y: CGFloat(y), z: CGFloat(z))