2
votes

I'm new to SceneKit coming from 2D SpriteKit and was trying to figure out how to adjust the camera so that it's at the top of the world facing down. I have the location part right, however on the rotation I'm getting stuck. If I adjust the X,YorZaxis, nothing seems to happen, however on the W axis the slightest change (even0.1` higher or lower) seems to move the camera in an unknown direction. What am I doing wrong?

cameraNode.position = SCNVector3Make(0, 10, 0)
cameraNode.rotation = SCNVector4Make(0, 0, 0, 0.5)
1

1 Answers

8
votes

the rotation vector is decomposed as (x_axis, y_axis, z_axis, angle)

Setting a rotation axis with a null angle is the identity (no effective rotation). Setting an angle with a null rotation axis does not actually define a rotation.

As for why a small change of the angle has a huge effect, it's because they are expressed in radians.

A rotation of 90º around the x axis can be achieved as follows

node.rotation = SCNVector4Make(1, 0, 0, M_PI_2)

But you can also use Euler angles (see SCNNode.eulerAngles) if you find it easier:

node.eulerAngles = SCNVector3Make(M_PI_2, 0, 0)