本文介绍了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)像素的视口rez (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场景或适合移动设备的网页时经常使用 viewports . 在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 viewportSize = sceneView.snapshot().size

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

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

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

let viewSize = sceneView.bounds.size

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

iPhone 7中的视口Rez(1/4)与屏幕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 ) 9倍 屏幕分辨率( 1125 x 2436 ).


在ViewPort的命中测试和射线投射坐标中使用.

让我们使用命中测试方法进行3次敲击-第一次敲击左上角(在x=0y=0附近),第二次敲击在屏幕中央,第三次敲击在右下角(在和y=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 –视口大小与实际屏幕分辨率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 22:42