4

So far, I figured out how to convert a local node position to global values in Swift (worldTransform).

My question is: How can I convert it the other way round? (due to rotation, x/y/z axis of the childnodes might be altered).

I know it has something to do with convertPosition, but I can't find any reference that helps me understanding it.

This is what I want to do: Node A is a child of rootNode and has a position A. Node B is a child of rootNode and has a position B and a rotation B. Node B1 is a childnode of Node B with local coordinates within it. I want to move Node B1 to Node A's position and replace it.

How do I translate Node A's coordinates to the local system of Node B?

Cheers

Sebastian
  • 417
  • 7
  • 8

1 Answers1

5

you have to express the new transform in the coordinate system of nodeB1's parent, and from

  1. either the coordinates system of nodeA's parent

    nodeB1.transform = [nodeB1.parentNode convertTransform:nodeA.transform fromNode:nodeA.parentNode];

  2. or the world coordinates system

    nodeB1.transform = [nodeB1.parentNode convertTransform:nodeA.worldTransform fromNode:nil];

of course you can replace nodeB1.parentNode by nodeB, and in this case nodeA's parent is the root node

mnuages
  • 13,049
  • 2
  • 23
  • 40