0

I am working on 3D project/unproject logic and I am learning some of the fundamentals. I went over this question:

Scene Kit: projectPoint calculated is displaced

In that question part of the shown code is:

//world coordinates
let v1w =  topSphereNode.convertPosition(v1, toNode: scene.rootNode)
let v2w =  topSphereNode.convertPosition(v2, toNode: scene.rootNode)

My question is, why is that needed? Why not just use v1 and v2 as points since they are already valid points 3D points in the scene? Why does the top sphere node's position need to be converted with respect to the root node's position?

zumzum
  • 17,984
  • 26
  • 111
  • 172

1 Answers1

0

since they are already valid points 3D points in the scene?

They are not necessarily valid 3D points in the scene, but 3D points in the local space of the sphere. The code you showed converts them to the world space, i.e. the scene space. This is important when the sphere is a child object, rotated, scaled, and/or simply not in the center of the scene.

Rather then using code from a question, check out the answers here: How to use iOS (Swift) SceneKit SCNSceneRenderer unprojectPoint properly

Xartec
  • 2,369
  • 11
  • 22