Reputation: 75
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:
Upvotes: 2
Views: 2536
Reputation: 58553
Let's explore some important display characteristics of your iPhone 7:
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 screenSize = 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 viewportSize = 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).
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!
Upvotes: 9