I'm trying to convert the 3d position of a nested SCNNode in to an x, y (CGPoint) coordinate (for overlaying a view over the object).
My SCNNode structure looks like:
+-----------+
| Root node |
+-----+-----+
|
|
+----+---+
+--+ Node A +--+
| +--------+ |
| |
| |
| |
+---+----+ +----+---+
| Node B | | Node C |
+--------+ +--------+
I'd like to get the screen space 2d position of NodeB. I'm aware of the convertPosition: and projectPoint: methods but I don't think I'm using them correctly.
Any pointers?
Edit:
Currently trying something like this:
SCNVector3 rootPosition = [[[[self view3D] scene] rootNode] convertPosition:[nodeB position] fromNode:nodeB];
SCNVector3 projectedPoint = [[self view3D] projectPoint:rootPosition];
NSLog(@"x %f y %f z %f", projectedPoint.x, projectedPoint.y, projectedPoint.z);
The resulting x, y, z are way off (and sometimes negative, which doesn't make sense in screen space as the object is plainly in view).