SceneKit - What orthographicProjection to use for 1:1 points to SceneKit position ratio

旧巷老猫 提交于 2019-12-21 22:04:14

问题


What orthographicProjection does one have to use to be able to make a 2D application in SceneKit with 1:1 SceneKit points to screen points/pixels ratio?

Example: I want to position something at (200, 200) on the screen and I want to use a SCNVector with (200, 200, 0) for it. What orthographicProjection do I need for this?


回答1:


If you want an orthographic projection where a unit of scene space corresponds to a point of screen space, you need a projection where the left clipping plane is at zero and the right clipping plane is at whatever the screen's width in points is. (Ditto for top/bottom, and near/far doesn't matter so long as you keep objects within whatever near/far you set up.)

For this it's probably easiest to set up your own projection matrix, rather than working out what orthographicScale and camera position correspond to the dimensions you need:

GLKMatrix4 mat = GLKMatrix4MakeOrtho(0, self.view.bounds.size.width,
                                     0, self.view.bounds.size.height,
                                     1, 100); // z range arbitrary
cameraNode.camera.projectionTransform = SCNMatrix4FromGLKMatrix4(mat);
// still need to position the camera for its direction & z range
cameraNode.position = SCNVector3Make(0, 0, 50); 


来源:https://stackoverflow.com/questions/29456861/scenekit-what-orthographicprojection-to-use-for-11-points-to-scenekit-positio

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