Can I get the SCNView camera position when using allowsCameraControl?

拥有回忆 提交于 2019-12-07 05:19:46

问题


The SCNView documentation says that setting allowsCameraControl to YES does not update the camera node position when the user changes the point of view. Is there any way to get the user-modified camera parameters when the user changes the point of view?


回答1:


When you enable allowsCameraControl, SceneKit inserts its own camera node into the scene (as an immediate child of the scene's root node), and sets that node as the view's pointOfView. Read the properties of that node to find out the camera's position and orientation, or the properties of the node's camera attribute to find the camera's field of view, depth limits, etc.




回答2:


Assuming mySCNView is the SCNView..

@property (weak, nonatomic) IBOutlet SCNView *mySCNView;

Then you can get the camera position from..

NSLog(@"Camera position: %f %f %f", _mySCNView.pointOfView.position.x, _mySCNView.pointOfView.position.y, _mySCNView.pointOfView.position.z);

NSLog(@"Camera rotation: %f %f %f %f", _mySCNView.pointOfView.rotation.x, _mySCNView.pointOfView.rotation.y, _mySCNView.pointOfView.rotation.z, _mySCNView.pointOfView.rotation.w);

NSLog(@"Camera orientat: %f %f %f %f", _mySCNView.pointOfView.orientation.x, _mySCNView.pointOfView.orientation.y, _mySCNView.pointOfView.orientation.z,_mySCNView.pointOfView.orientation.w);

In my case, I turned on allowsCameraControl and adjusted the view, noted down the values, and set them at the start of the app. I only needed to set position and orientation, not rotation.



来源:https://stackoverflow.com/questions/24768031/can-i-get-the-scnview-camera-position-when-using-allowscameracontrol

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!