ARKit – Viewport Size vs Real Screen Resolution

℡╲_俬逩灬. 提交于 2020-05-28 07:45:09

问题


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

I notices when I do:

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

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

The questions are:

  • 1.Why there is a difference?
  • 2.What "size" (e.g. coordinates) is used in hitTest?

回答1:


Why there is a difference?

Let's explore some important display characteristics of your iPhone 7:

  • a resolution of 750 (W) x 1,334 (H) pixels (16 : 9)
  • viewport rez of 375 (W) x 667 (H) pixels (16 : 9)

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.

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.

Snapshots almost always reflect a real screen resolutions:

let viewportSize = sceneView.snapshot().size

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

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

let viewSize = sceneView.bounds.size 

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

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

Schematic depiction!

Viewport size and its real layout in mobile device:

Real depiction!

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

What coordinates are used in Hit-Testing?

In Hit-Testing and Ray-Casting coordinates of ViewPort are used.

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)

Coordinates of iPhone 7 Viewport is printed in a console:

Quod Erat Demonstrandum!


来源:https://stackoverflow.com/questions/60731258/arkit-viewport-size-vs-real-screen-resolution

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!