3

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.

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
Anson Yao
  • 1,544
  • 17
  • 27

1 Answers1

4

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.

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
  • 1
    Great answer to use the docs. Only change I would make is to link to the page in the docs that this has come from :) – Fogmeister Oct 12 '18 at 12:37
  • Sorry, but the equation part of this answer seems wrong to me: If (x * x) + (y * y) + (z * z) + (w * w) == 1 must be always satisfied, then SCNQuaterion(0,0,0,0) would be impossible. But of course a SCNQuaterionZero exits, it actually is the start value of any SCNNode in a SCNScene. – LukeSideWalker Jan 27 '21 at 20:11
  • Hi @LukeSideWalker! Here's Apple info: https://developer.apple.com/documentation/scenekit/scnquaternion – Andy Jazz Jan 27 '21 at 20:25
  • Hi @AndyFedoroff thanks for replying so quickly. But my point is still right. If you read the docs from Apple correct, then it says: "SceneKit uses unit quaternions ..." and this is the important part: ONLY those 'unit quaternions' satisfy the equation, not ALL quaternions. It is like "normalized" vectors, they have always the length of 1, but not any possible vector, only the "normalized". – LukeSideWalker Jan 27 '21 at 20:31
  • In my answer I wrote about `SceneKit's unit quaternions`. – Andy Jazz Jan 27 '21 at 20:32
  • 1
    Hi @AndyFedoroff, I am sorry, I just saw, that you correctly quoted Apples docs. I let my comment nevertheless, because it is important, that ONLY those specific "unit quaternions" satisfy the mentioned equation. – LukeSideWalker Jan 27 '21 at 20:34
  • Thanks a lot @LukeSideWalker, I'll correct this section of my answer. – Andy Jazz Jan 27 '21 at 20:39