SCNNode中的Orientation和Rotation有什么区别 [英] What is the difference between Orientation and Rotation in SCNNode

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

问题描述

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

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

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

Apple doc 说:旋转、eulerAngles 和方向属性都会影响节点变换属性的旋转方面.对这些属性之一的任何更改都会反映在其他属性中.

所以他们控制相同的东西但使用不同的格式?这是我目前的理解.但是如何?它们都是 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.0.E.comm 提到它保留了四元数的定义,但 w 表示 SCNVector4 中用于旋转的旋转度数.所以我不确定它为什么会在那里,因为我没有在我的代码中旋转节点.

解决方案

SceneKit 框架中的 OrientationRotation 之间有一些明显的区别.方向表示为一个四元数(等式的结果必须是1).

根据 Apple 文档:

<块引用>

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

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

SceneKit 使用 单位四元数——那些组件满足方程的元素:

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

用于节点的方向属性.

varorientation: SCNQuaternion { get set }//实例属性//结构体 `float4` 中有四个元素 (x, y, z, w)var 方向:SCNQuaternion = SCNQuaternion(v: float4)typealias SCNQuaternion = SCNVector4

<块引用>

Rotation – 节点的方向,表示为旋转角度关于一个轴.可动画.四分量旋转矢量在前三个分量中指定旋转轴的方向,在第四个分量中指定旋转角度(以弧度为单位).默认旋转是零向量,指定无旋转.相对于节点的枢轴属性应用旋转.

var rotation: SCNVector4 { get set }//实例属性var 旋转:SCNVector4 = SCNVector4(x: CGFloat,y:CGFloat,z: CGFloat,w: CGFloat)

如您所见,orientation 实例属性以SCNQuaternion 类型表示,而rotation 实例属性以SCNVector4 类型表示> 输入.

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.

解决方案

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.

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

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