How to get the real position of sub node in SceneKit after rotation?

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

// 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]; 

I use NSTimer to perform some actions and some animations. In the timer event, I do this:

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

But if I try to get the position of the satellite node, I always get the same value. I tried to find out that positionnode knows the actual position of the satellite node, but nothing changes.

How can I get the real position under the node when I change the rotation of the parent node?

Thanks in advance

+5
source share
2 answers

the position of a node is expressed in the original coordinate system. As well as for views in UIKIt / AppKit. If you change the presentation frame, the frame of its subzones will not change.

What you want is what we call the global transformation of the subnode (i.e. its transformation, expressed in the coordinate system of the root of the scene node).

You can look at worldTransform and -convertPosition:toNode:

+6
source

The position of the node will not change due to physics, so you do not see its change. You must call node presentationNode to get the node position, since it is presented on the screen:

 node.presentationNode.position 
+3
source

Source: https://habr.com/ru/post/1206356/


All Articles