I have this app that just works in landscape.
I have an object on scenekit. That object is at a certain position, specified by:
SCNNode * buttonRef = [scene.rootNode childNodeWithName:@"buttonRef" recursively:YES];
SCNVector3 buttonRefPosition = [buttonRef position];
Now I need to convert that SCNVector3
to mainView
2D coordinates, where
mainView = (SCNView *)self.view;
The scene is using orthogonal camera, so no perspective. The camera is the default camera. No rotation, no translation. Camera's orthographicScale is 5.4.
How do I convert that?
I have found other answers on SO about the reverse question, that is converting from CGPoint to SCNVector3 but doesn't sound obvious to me how to do the reverse, from SCNVector3 to CGPoint.
If the SCNView is a subclass of UIView, than (0,0) is the upper left point and in the case of the iPhone 6 landscape, (667, 375) is the lower right point.
This button of mine is at almost full right and middle of height. In terms of UIKit I would say that this button is at (600, 187) but when I do this:
SCNNode * buttonRef = [scene.rootNode childNodeWithName:@"buttonRef" recursively:YES];
SCNVector3 buttonRefPosition = [buttonRef position];
SCNVector3 projectedPoint = [mainView projectPoint: buttonRefPosition];
I get projectPoint equal to (7.8, 375, 0) (?)
and when I add a 10x10 view to the coordinate (7.8, 375) using UIKit, I get a view at the lower left!!
Like I said the app is operating in landscape only but these coordinate systems are all messed.
buttonRef
node geometry a SceneKit object (SCNSphere
,SCNBox
, etc) or something created in a 3D modelling tool and loaded as a dae file? All the SceneKit objects have an origin at 0,0,0 (by that I mean a sphere's centre is located at 0,0,0), it may be that the model you're using has geometry that is not centred about 0. A quick way to check would be to add a smallSCNSphere
as a child of your buttonRef node and confirm it appears where you think the origin of your geometry is. FWIWprojectPoint
returns expected 2D coords in my app. – lock[scnView projectPoint:SCNVector3Zero];
or in other words I am projecting 0,0,0. The projection gives me (0, 375, 0). How can 0,0,0 on scenekit – that in my case is what is visible in the exact center of the camera be (0,375,0) or in fact (0,375) on UIKit? ... that is a point on the right down? – Duck