ARKit – 视口大小与实际屏幕分辨率 [英] ARKit – Viewport Size vs Real Screen Resolution

查看:28
本文介绍了ARKit – 视口大小与实际屏幕分辨率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个使用 ARSCNView hitTest 函数的 ARKit 应用程序.该应用还将捕获的图像发送到服务器进行一些分析.

I am writing an ARKit app that uses ARSCNView hitTest function. Also the app sends captured images to the server for some analysis.

我会注意到:

let viewportSize = sceneView.snapshot().size
let viewSize = sceneView.bounds.size 

那么第一个是第二个的两倍.

then the first one is twice as large as the second one.

问题是:

  • 1.为什么会有不同?
  • 2.hitTest 中使用了什么大小"(例如坐标)?

推荐答案

为什么会有区别?

让我们探索一下 iPhone 7 的一些重要显示特性:

  • 分辨率为 750 (W) x 1,334 (H) 像素 (16 : 9)
  • 视口分辨率为 375 (W) x 667 (H) 像素 (16 : 9)
  • a resolution of 750 (W) x 1,334 (H) pixels (16 : 9)
  • viewport rez of 375 (W) x 667 (H) pixels (16 : 9)

由于具有相同屏幕尺寸的移动设备可能具有非常不同的分辨率,因此开发人员在创建 3D 场景或移动友好网页时经常使用视口.在 VR 和 AR 领域:分辨率越低 - 渲染器越快,CPU/GPU 负担显着减轻.创建视口的想法主要用于移动设备.在 macOS 中 Screen ResolutionViewport Resolution 是相同的.

Because mobile devices with the same screen size can have very different resolutions, developers often use viewports when they are creating 3D scenes or mobile friendly webpages. In VR and AR fields: the lower resolution is – the quicker a renderer is, and CPU/GPU burden is considerably less. The idea of creating viewports is mainly used for mobile devices. In macOS Screen Resolution and Viewport Resolution are identical.

在 iPhone 和其他移动设备中,Viewport 是分辨率的缩小版本(通常每个轴缩小 2 或 3 倍),允许 3D场景视口或网站可以在不同设备上更一致地查看,并且(非常重要!)能源消耗更少.视口通常比分辨率尺寸更标准化且更小.

In iPhone, as well as in other mobile devices, Viewport is a scaled down version (usually 2 or 3 times smaller in each axis) of resolution that allows 3D scenes viewports or websites to be viewed more consistently across different devices and (very important!) with less energy's consumption. Viewports are often more standardized and smaller than resolution sizes.

快照几乎总是反映真实的屏幕分辨率:

let screenSize = sceneView.snapshot().size

/*   750 x 1,334    */
/*   iPhone 7 rez   */

SceneView 大小通常反映了标准化的屏幕分辨率(比 specs rez 小 4 倍):

SceneView size often reflects a standardized screen resolution (4 times smaller than specs rez):

let viewportSize = sceneView.bounds.size 

/*   375 x 667     */
/*   ViewPort rez  */

iPhone 7 中的 Viewport Rez (1/4) 与 Screen Rez 的纵横比:

Viewport Rez (1/4) to Screen Rez aspect ratio in iPhone 7:

示意图!

视口大小及其在移动设备中的真实布局:

Viewport size and its real layout in mobile device:

真实写照!

其他参考:Phone X 的 ViewPort 分辨率九倍较小 (375 x 812) 而不是屏幕分辨率 (1125 x 2436).

Additional reference: Phone X has a ViewPort resolution nine times smaller (375 x 812) than screen resolution (1125 x 2436).


在 Hit-Testing 和 Ray-Casting 中使用 ViewPort 坐标.

让我们使用命中测试方法进行 3 次敲击 - 第一次敲击左上角(靠近 x=0y=0),第二次敲击左上角的中心屏幕和右下角的第三次点击(靠近 x=667y=375):

Let's make 3 taps using hit-testing method – first tap in a Upper Left corner (near x=0 and y=0), second tap in center of the screen and third tap in a Lower Right Corner (near x=667 and y=375):

let point: CGPoint = gestureRecognize.location(in: sceneView)

print(point)

iPhone 7 Viewport 的坐标打印在控制台中:

Coordinates of iPhone 7 Viewport is printed in a console:

Quod Erat Demonstrandum!

这篇关于ARKit – 视口大小与实际屏幕分辨率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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