swiftaugmented-realityscenekitarkitvirtual-reality

What is the difference between Orientation and Rotation in SCNNode


I am quite confused by the "rotation" and "orientation" for a SCNNode. In Apple's doc, they are defined quite similarly:

orientation: The node’s orientation, expressed as a quaternion. Animatable.

rotation: The node’s orientation, expressed as a rotation angle about an axis. Animatable.

And apple doc says: The rotation, eulerAngles, and orientation properties all affect the rotational aspect of the node’s transform property. Any change to one of these properties is reflected in the others.

So they kind of control the same thing but are using different format? That is my current understanding. But how? They are both SCNVector4 type. I understand the rotation but I am not sure how to set the orientation and how it is different.

(EDIT)

I just tried to make a default node by SCNNode() and print out its rotation and orientation:

Rotation: SCNVector4(x: 0.0, y: 0.0, z: 0.0, w: 0.0)

Orientation: SCNVector4(x: 0.0, y: 0.0, z: 0.0, w: 1.0)

I am still not sure why there is 1.0. E.comm has mentioned that it keeps the definition of quaternion but that w means a rotation degree in SCNVector4 for rotation. So I am not sure why it is there since I did not rotate node in my code.


Solution

  • There's some obvious difference between Orientation and Rotation in SceneKit framework. Orientation is expressed as a quaternion (whose result of the equation must be 1).

    According to Apple documentation:

    Orientation – The node’s orientation, expressed as a quaternion. Animatable.

    A quaternion is a mathematical construct useful for describing rotations in three-dimensional space. Although its implementation differs from that of a 4-component vector, you specify a quaternion value using the same fields as an SCNVector4 structure.

    SceneKit uses unit quaternions – those whose components satisfy the equation:

    x² + y² + z² + w² == 1
    

    for the orientation property of nodes.

    var orientation: SCNQuaternion { get set }  // instance property
    
    // There are four elements (x, y, z, w) in Structure `float4`
    var orientation: SCNQuaternion = SCNQuaternion(v: float4)
    
    typealias SCNQuaternion = SCNVector4
    

    Rotation – The node’s orientation, expressed as a rotation angle about an axis. Animatable. The four-component rotation vector specifies the direction of the rotation axis in the first three components and the angle of rotation (in radians) in the fourth. The default rotation is the zero vector, specifying no rotation. Rotation is applied relative to the node’s pivot property.

    var rotation: SCNVector4 { get set }  // instance property
    
    var rotation: SCNVector4 = SCNVector4(x: CGFloat,
                                          y: CGFloat,
                                          z: CGFloat,
                                          w: CGFloat)
    

    As you can see orientation instance property is expressed in SCNQuaternion type but rotation instance property is expressed in SCNVector4 type.