I just started learning how to use SceneKit
yesterday, so I may get some stuff wrong or incorrect. I am trying to make my cameraNode
look at a SCNVector3
point in the scene.
I am trying to make my app available to people below iOS 11.0
. However, the look(at:)
function is only for iOS 11.0+
.
Here is my function where I initialise the camera:
func initCamera() {
cameraNode = SCNNode()
cameraNode.camera = SCNCamera()
cameraNode.position = SCNVector3(5, 12, 10)
if #available(iOS 11.0, *) {
cameraNode.look(at: SCNVector3(0, 5, 0)) // Calculate the look angle
} else {
// How can I calculate the orientation? <-----------
}
print(cameraNode.rotation) // Prints: SCNVector4(x: -0.7600127, y: 0.62465125, z: 0.17941462, w: 0.7226559)
gameScene.rootNode.addChildNode(cameraNode)
}
The orientation of SCNVector4(x: -0.7600127, y: 0.62465125, z: 0.17941462, w: 0.7226559)
in degrees is x: -43.5, y: 35.8, z: 10.3
, and I don't understand w
. (Also, why isn't z = 0
? I thought z
was the roll...?)
Here is my workings out for recreating what I thought the Y-angle should be:
So I worked it out to be 63.4 degrees
, but the returned rotation shows that it should be 35.8 degrees
. Is there something wrong with my calculations, do I not fully understand SCNVector4
, or is there another method to do this?
I looked at Explaining in Detail the ScnVector4 method for what SCNVector4
is, but I still don't really understand what w
is for. It says that w
is the 'angle of rotation' which I thought was what I thought X, Y & Z were for.
If you have any questions, please ask!