SCNNode 中的 Orientation 和 Rotation 有什么区别

What is the difference between Orientation and Rotation in SCNNode

我对 SCNNode 的 "rotation" 和 "orientation" 感到很困惑。在 Apple 的文档中,它们的定义非常相似:

orientation:节点的方向,用四元数表示。动画。

rotation:节点的方向,表示为绕轴的旋转角度。动画。

苹果文档说: rotation、eulerAngles 和 orientation 属性都会影响节点变换的旋转方面 属性。对这些属性之一的任何更改都会反映在其他属性中。

所以他们控制的是同一个东西,但使用的是不同的格式?这是我目前的理解。但是怎么办?它们都是 SCNVector4 类型。我了解旋转,但我不确定如何设置方向以及它有何不同。

(编辑)

我刚刚尝试通过 SCNNode() 创建一个默认节点并打印出它的旋转和方向:

旋转: SCNVector4(x: 0.0, y: 0.0, z: 0.0, w: 0.0)

定位: SCNVector4(x: 0.0, y: 0.0, z: 0.0, w: 1.0)

我仍然不确定为什么会有 1.0。 E.comm 提到它保留了四元数的定义,但 w 表示 SCNVector4 中旋转的旋转度数。所以我不确定为什么它在那里,因为我没有在我的代码中旋转节点。

在 SceneKit 框架中 OrientationRotation 之间有一些明显的区别。 方向表示为quaternion(其等式的结果必须是1)。

根据 Apple 文档

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

四元数是一种数学结构,可用于描述三维 space 中的旋转。虽然它的实现与 4 分量向量的实现不同,但您可以使用与 SCNVector4 结构相同的字段指定四元数值。

SceneKit 使用 unit quaternions – 那些组件满足等式:

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

节点的方向 属性。

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)

如您所见,orientation 实例 属性 以 SCNQuaternion 类型表示,但 rotation 实例 属性 以 SCNVector4 类型表示.