What is the difference between Orientation and Rotation in SCNNode

天大地大妈咪最大 提交于 2020-12-06 06:35:22

问题


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.


回答1:


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 * x) + (y * y) + (z * z) + (w * 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.



来源:https://stackoverflow.com/questions/52768681/what-is-the-difference-between-orientation-and-rotation-in-scnnode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!