SceneKit - 用于 1:1 的 orthographicProjection 指向 SceneKit 位置比 [英] SceneKit - What orthographicProjection to use for 1:1 points to SceneKit position ratio
问题描述
必须使用什么 orthographicProjection 才能在 SceneKit 中制作具有 1:1 SceneKit 指向屏幕点/像素比的 2D 应用程序?
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?
示例:我想在屏幕上的 (200, 200) 处定位一些东西,我想使用一个带有 (200, 200, 0) 的 SCNVector .为此我需要什么正交投影?
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?
推荐答案
如果你想要一个场景空间单位对应屏幕空间一个点的正交投影,你需要一个左裁剪平面为零的投影,并且正确的剪切平面位于以点为单位的屏幕宽度.(顶部/底部和近/远都没有关系,只要您将对象保持在您设置的任何近/远范围内即可.)
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.)
为此,设置您自己的投影矩阵可能是最简单的,而不是计算出什么orthographicScale
和相机位置对应于您需要的尺寸:
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);
这篇关于SceneKit - 用于 1:1 的 orthographicProjection 指向 SceneKit 位置比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!