SceneKit - 用于1:1的orthographicProjection指向SceneKit位置比率 [英] SceneKit - What orthographicProjection to use for 1:1 points to SceneKit position ratio

查看:214
本文介绍了SceneKit - 用于1:1的orthographicProjection指向SceneKit位置比率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

必须使用什么orthographicProjection才能在SceneKit中以1:1的方式制作2D应用程序SceneKit指向屏幕点/像素比率?

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。我需要什么orthographicProjection?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆