Swift - How to change the Pivot of a SCNNode object(Swift - 如何更改 SCNNode 对象的 Pivot)
问题描述
我玩 SCNNode 对象已经有一段时间了,但我对 Pivot 感到迷茫.如何更改 SCNNode(SCNBox 作为条形)的轴心并将轴心放置在条形的边缘之一上?
I've been playing with the SCNNode object for a while now and I'm lost with the Pivot. How can I change the pivot of a SCNNode (SCNBox as a bar) and place the pivot on one of the edge of the bar?
推荐答案
一个节点的pivot
是一个变换矩阵,它的逆被应用到它的transform
属性生效.例如,看一下 Xcode 中默认的 SceneKit 游戏模板中的这一点:
A node's pivot
is a transformation matrix, the inverse of which is applied to the node before its transform
property takes effect. For example, take a look at this bit from the default SceneKit Game template in Xcode:
let boxNode = SCNNode()
boxNode.geometry = SCNBox(width: 1, height: 1, length: 1, chamferRadius: 0.02)
如果你设置boxNode
的position
,那个点对应立方体的中心,如果你旋转它(就像模板在动画中做的那样),它围绕它的中心旋转.
If you set the boxNode
's position
, that point corresponds to the center of the cube, and if you rotate it (as the template does in an animation), it spins around its center.
要更改锚点,请将 pivot
设置为平移变换:
To change the anchor point, set the pivot
to a translation transform:
boxNode.pivot = SCNMatrix4MakeTranslation(0.5, 0.5, 0.5)
现在,当您设置 position
时,该点对应于立方体的右上角,当您旋转立方体时,它会围绕该角旋转.
Now, when you set the position
that point corresponds to the top-right-front corner of the cube, and when you rotate the cube it spins around that corner.
更一般地说,枢轴会相对于节点自身的变换来变换节点的内容.假设您想要模拟地球自转轴的岁差.您可以通过创建两个动画来做到这一点:一个动画 pivot
使节点围绕其自己的 Y 轴旋转,另一个动画 rotation
动画以相对于空间移动该轴包含节点.
More generally, a pivot transforms the contents of a node relative to the node's own transform. Suppose you wanted to model the precession of the Earth's axis of rotation. You could do this by creating two animations: one that animates pivot
to spin the node around its own Y axis, and another that animates rotation
to move that axis relative to the space containing the node.
这篇关于Swift - 如何更改 SCNNode 对象的 Pivot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Swift - 如何更改 SCNNode 对象的 Pivot
基础教程推荐
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01