Skip to content
This repository was archived by the owner on Dec 15, 2020. It is now read-only.

Commit f92ebec

Browse files
handle orientation change of window when computing FOV
Summary: When the orientation of the window changes the fov would be computed as 60deg over less pixels so the text screen size would shrink handle orientation and attempt to preserve the correct fov. A clamp of the computed fov is applied to make sure very small or very large values are used in projection matrix Differential Revision: D4964479 fbshipit-source-id: 34b6cd1
1 parent 9e450db commit f92ebec

1 file changed

Lines changed: 53 additions & 1 deletion

File tree

OVRUI/src/Player/Player.js

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,36 @@ function isWebGLSupported() {
7373
return !!gl;
7474
}
7575

76+
function isMobileInLandscapeOrientation() {
77+
// functionality required for mobile only
78+
if (!isMobile) {
79+
return false;
80+
}
81+
82+
// use draft screen.orientation type to determine if mobile is landscape orientation
83+
var orientation = screen.orientation || screen.mozOrientation || screen.msOrientation;
84+
if (orientation) {
85+
if (orientation.type === 'landscape-primary' || orientation.type === 'landscape-secondary') {
86+
return true;
87+
} else if (orientation.type === 'portrait-secondary' || orientation.type === 'portrait-primary') {
88+
return false;
89+
}
90+
}
91+
92+
// fall back to window.orientation
93+
if (!window.orientation) {
94+
return false;
95+
}
96+
let quadrant = Math.round(window.orientation / 90);
97+
while (quadrant < 0) {
98+
quadrant += 4;
99+
}
100+
while (quadrant >= 4) {
101+
quadrant -= 4;
102+
}
103+
return quadrant === 1 || quadrant === 3;
104+
}
105+
76106
/**
77107
* A Player wraps most of the boilerplate of setting up an embedded VR
78108
* experience. It constructs a Three.js renderer, and attaches it to the
@@ -106,6 +136,7 @@ export default class Player {
106136

107137
this.isMobile = isMobile;
108138
this.allowCarmelDeeplink = !!options.allowCarmelDeeplink && isSamsung;
139+
this.calculateVerticalFOV = options.calculateVerticalFOV;
109140

110141
let width = options.width;
111142
let height = options.height;
@@ -167,7 +198,17 @@ export default class Player {
167198
// Use a single eye camera with a normal FoV but set the depthNear/depthFar
168199
// based on our spec defaults to prevent browser renders differing from our
169200
// VRDisplay renders.
170-
this._camera = new THREE.PerspectiveCamera(60, width / height, 0.01, 10000.0);
201+
let fov;
202+
if (isMobileInLandscapeOrientation()) {
203+
// clamp range of fov to be reasonable
204+
fov = Math.max(30, Math.min(70, 60 / (width / height)));
205+
} else {
206+
fov = 60;
207+
}
208+
if (typeof this.calculateVerticalFOV === 'function') {
209+
fov = this.calculateVerticalFOV(width, height);
210+
}
211+
this._camera = new THREE.PerspectiveCamera(fov, width / height, 0.01, 10000.0);
171212
}
172213
this._initialAngles = {
173214
x: this._camera.rotation.x,
@@ -535,6 +576,17 @@ export default class Player {
535576
}
536577
this.glRenderer.setPixelRatio(this.pixelRatio);
537578
this.glRenderer.setSize(width, height, true);
579+
let fov;
580+
if (isMobileInLandscapeOrientation()) {
581+
// clamp the range of fov
582+
fov = Math.max(30, Math.min(70, 60 / (width / height)));
583+
} else {
584+
fov = 60;
585+
}
586+
if (typeof this.calculateVerticalFOV === 'function') {
587+
fov = this.calculateVerticalFOV(width, height);
588+
}
589+
this._camera.fov = fov;
538590
this._camera.aspect = width / height;
539591
this._camera.updateProjectionMatrix();
540592
}

0 commit comments

Comments
 (0)