SCNNode中的“方向"和“旋转"之间有什么区别 [英] What is the difference between Orientation and Rotation in SCNNode

查看:72
本文介绍了SCNNode中的“方向"和“旋转"之间有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对SCNNode的旋转"和方向"感到非常困惑.在Apple的文档中,它们的定义非常相似:

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

orientation:节点的方向,以四元数表示.可动画的.

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

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

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

苹果医生说:旋转,eulerAngles和方向属性都会影响节点的transform属性的旋转方面.这些属性之一的任何更改都会反映在其他属性中.

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.

那么他们有点控制相同的东西,但是使用不同的格式?那是我目前的理解.但是如何?它们都是SCNVector4类型.我了解旋转方式,但不确定如何设置方向以及它如何不同.

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.

(编辑)

我只是尝试通过SCNNode()创建一个默认节点,并打印出其旋转方向和方向:

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

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

Rotation: 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)

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

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

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.

推荐答案

SceneKit框架中的 Orientation Rotation 之间存在一些明显的区别.方向表示为四元数(等式的结果必须为 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).

根据Apple文档:

方向 –节点的方向,以四元数表示.可动画的.

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

四元数是一种数学构造,可用于描述三维空间中的旋转.尽管其实现与4分量矢量的实现不同,但是您可以使用与SCNVector4结构相同的字段来指定四元数值.

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使用单位四元数 –满足其方程的那些四元数

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

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 类型.

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

这篇关于SCNNode中的“方向"和“旋转"之间有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆