旋转后如何获取SceneKit中子节点的实际位置? [英] How to get the real position of a sub node in SceneKit after rotation?

查看:94
本文介绍了旋转后如何获取SceneKit中子节点的实际位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用SceneKit开发场景.我有一个带有子节点的主节点:

I am developing a scene with SceneKit. I have a main node with a subnode:

// Main node
SCNNode* planet = [SCNNode node];
planet.geometry = [SCNSphere sphereWithRadius:2];
planet.position = SCNVector3Make(0, -3, 5);
// sub-node
SCNNode* satellite = [SCNNode node];
satellite.geometry = [SCNSphere sphereWithRadius:0.4];
satellite.position = SCNVector3Make(4, 0, 0);
[planet addChildNode:satellite];
[scene.rootNode addChildNode:planet];

我使用NSTimer进行一些动作和一些动画处理.在计时器事件中,我这样做:

I use a NSTimer to make some actions and some animations. In the timer event I do that:

planetRotation + = 0.1; planet.rotation = SCNVector4Make(0,1,0,planetRotation);

planetRotation += 0.1; planet.rotation = SCNVector4Make(0,1,0, planetRotation);

但是,如果我尝试获取卫星节点的位置,我总是会得到相同的值. 我试图让positionnode知道卫星节点的真实位置,但是没有任何变化.

But if i try to get the position of the satellite node I always get the same value. I tried to get the positionnode to know the real position of the satellite node but nothing changes.

更改父节点的旋转方式后,如何获得子节点的真实位置?

How can I get the real position of a sub-node when I change the rotation of the parent node?

预先感谢

推荐答案

节点的位置在其父坐标系中表示.就像UIKIt/AppKit中的视图一样.如果更改视图的框架,则其子视图的框架不会改变.

the position of a node is expressed in its parent coordinate system. Just like for views in UIKIt/AppKit. If you change the frame of a view, the frame of its subviews does not change.

您想要的就是我们所说的子节点的世界变换(即,以场景根节点的坐标系表示的变换).

What you want is what we call the world transform of the subnode (i.e. its transform expressed in the coordinate system of the scene's root node).

您可以查看

You can have a look at worldTransform and -convertPosition:toNode:.

这篇关于旋转后如何获取SceneKit中子节点的实际位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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