ios - SceneKit - 什么 orthographicProjection 用于 1 :1 points to SceneKit position ratio

标签 ios objective-c xcode 3d scenekit

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

例子: 我想在屏幕上的 (200, 200) 位置放置一些东西,我想为它使用带有 (200, 200, 0) 的 SCNVector。为此,我需要什么 orthographicProjection?

最佳答案

如果您想要一个场景空间单位对应于屏幕空间点的正交投影,您需要一个投影,其中左裁剪平面为零,右裁剪平面为屏幕宽度(以磅为单位)。 (对于顶部/底部和近/远并不重要,只要您将对象保持在您设置的近/远范围内即可。)

为此,最简单的方法可能是设置您自己的投影矩阵,而不是计算出与您需要的尺寸相对应的 orthographicScale 和相机位置:

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); 

关于ios - SceneKit - 什么 orthographicProjection 用于 1 :1 points to SceneKit position ratio,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29456861/

相关文章:

iphone - 使用 "User Defined Runtime Attributes"在 Storyboard中本地化 View

ios - Alamofire 使用未声明的类型 'Serializer'

objective-c - NSTimer未失效

ios - 使用 AutoLayout 调整 UICollectionViewCell 及其内容的大小

objective-c - 在 Xcode 中为 iPad 指定图像,例如为 iPhone 4 指定 @2x

objective-c - 从 View Controller 外部调用 macOS 中的 View

iphone - 由于未捕获的异常 'NSInvalidArgumentException' 而终止应用程序,原因 : 'Receiver () has no segue with identifier ' pizzaSegue'

ios - 在 initWithCoder : 上查看 1000x1000

objective-c - 我如何在 Xcode 中找到特定函数的所有调用函数,如 eclipse 的调用层次结构?

ios - 使用 UITextField 理解 resignFirstResponder