From 0fcc474bb619f6704a20b7319759487ac76fe63d Mon Sep 17 00:00:00 2001 From: IhorDyntu Date: Thu, 5 Sep 2019 15:54:14 +0300 Subject: [PATCH 1/4] fixed image splitting in VR --- Source/Scene/Scene.js | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/Source/Scene/Scene.js b/Source/Scene/Scene.js index 7b5d3b0e3a39..059bb7ecf168 100644 --- a/Source/Scene/Scene.js +++ b/Source/Scene/Scene.js @@ -2682,23 +2682,49 @@ define([ savedCamera.frustum = camera.frustum; var near = camera.frustum.near; + var far = camera.frustum.far; var fo = near * defaultValue(scene.focalLength, 5.0); var eyeSeparation = defaultValue(scene.eyeSeparation, fo / 30.0); var eyeTranslation = Cartesian3.multiplyByScalar(savedCamera.right, eyeSeparation * 0.5, scratchEyeTranslation); - camera.frustum.aspectRatio = viewport.width / viewport.height; + var aspectRatio = camera.frustum.aspectRatio = viewport.width / viewport.height; + var widthdiv2 = near * Math.tan(camera.frustum.fov / 2); var offset = 0.5 * eyeSeparation * near / fo; Cartesian3.add(savedCamera.position, eyeTranslation, camera.position); - camera.frustum.xOffset = offset; + + var left = - aspectRatio * widthdiv2 - offset; + var right = aspectRatio * widthdiv2 - offset; + var top = widthdiv2; + var bottom = - widthdiv2; + camera.frustum = new PerspectiveOffCenterFrustum({ + left: left, + right: right, + top: top, + bottom: bottom, + near: near, + far: far + }); executeCommands(scene, passState); viewport.x = viewport.width; Cartesian3.subtract(savedCamera.position, eyeTranslation, camera.position); - camera.frustum.xOffset = -offset; + + left = - aspectRatio * widthdiv2 + offset; + right = aspectRatio * widthdiv2 + offset; + top = widthdiv2; + bottom = - widthdiv2; + camera.frustum = new PerspectiveOffCenterFrustum({ + left: left, + right: right, + top: top, + bottom: bottom, + near: near, + far: far + }); executeCommands(scene, passState); From 6ce49f007d55bb966d20ac36b01e319e75ed7403 Mon Sep 17 00:00:00 2001 From: IhorDyntu Date: Thu, 5 Sep 2019 16:35:51 +0300 Subject: [PATCH 2/4] updated contributors.md --- CONTRIBUTORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 7a3e152689d2..133716b99ed2 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -226,3 +226,4 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to Cesiu * [Pascal Poulain](https://github.com/ppoulainpro) * [Abu Darda](https://github.com/abuDarda97) * [jony89](https://github.com/jony89) +* [SorryNotSorryBasileus](https://github.com/SorryNotSorryBasileus) From 7d1a91bdbcba7b3ea588534b2effa4b73e2d08a2 Mon Sep 17 00:00:00 2001 From: IhorDyntu Date: Thu, 12 Dec 2019 15:34:03 +0200 Subject: [PATCH 3/4] trigger appveyor From bec06174e2847cb65c2f258c5f7eca924b8b38bf Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Mon, 2 Mar 2020 19:02:39 -0500 Subject: [PATCH 4/4] Cleanup --- CHANGES.md | 6 +++++ CONTRIBUTORS.md | 2 +- Source/Scene/Camera.js | 7 +++++- Source/Scene/Scene.js | 53 +++++++++++++++++++++--------------------- 4 files changed, 40 insertions(+), 28 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index f6cf17687bd9..77eb015526d2 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,12 @@ Change Log ========== +### 1.68 - 2020-04-01 + +##### Fixes :wrench: + +* Fixed image splitting in VR mode. [#8138](https://github.com/CesiumGS/cesium/pull/8138) + ### 1.67.0 - 2020-03-02 ##### Breaking Changes :mega: diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 26fbbe5f89f8..0584473c9caf 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -248,4 +248,4 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to Cesiu * [Ricardo Morin](https://github.com/jimmyangel) * [Jan Wąsak](https://github.com/jhnwsk) * [Julian Fell](https://github.com/jtfell) -* [Richard Becker](https://github.com/richard3d) \ No newline at end of file +* [Richard Becker](https://github.com/richard3d) diff --git a/Source/Scene/Camera.js b/Source/Scene/Camera.js index 413c9a7b7e40..973d81a9fc55 100644 --- a/Source/Scene/Camera.js +++ b/Source/Scene/Camera.js @@ -3206,7 +3206,12 @@ import SceneMode from './SceneMode.js'; Cartesian3.clone(camera.right, result.right); Matrix4.clone(camera._transform, result.transform); result._transformChanged = true; - result.frustum = camera.frustum.clone(); + + if (result.frustum.constructor === camera.frustum.constructor) { + result.frustum = camera.frustum.clone(result.frustum); + } else { + result.frustum = camera.frustum.clone(); + } return result; }; diff --git a/Source/Scene/Scene.js b/Source/Scene/Scene.js index c4f46acdf5db..5f2bb8c089d4 100644 --- a/Source/Scene/Scene.js +++ b/Source/Scene/Scene.js @@ -2648,6 +2648,8 @@ import View from './View.js'; } }; + var scratchVRFrustum = new PerspectiveOffCenterFrustum(); + function executeWebVRCommands(scene, passState, backgroundColor) { var view = scene._view; var camera = view.camera; @@ -2684,24 +2686,24 @@ import View from './View.js'; var eyeTranslation = Cartesian3.multiplyByScalar(savedCamera.right, eyeSeparation * 0.5, scratchEyeTranslation); var aspectRatio = camera.frustum.aspectRatio = viewport.width / viewport.height; - var widthdiv2 = near * Math.tan(camera.frustum.fov / 2); - + var widthOverTwo = near * Math.tan(camera.frustum.fov / 2.0); var offset = 0.5 * eyeSeparation * near / fo; Cartesian3.add(savedCamera.position, eyeTranslation, camera.position); - var left = - aspectRatio * widthdiv2 - offset; - var right = aspectRatio * widthdiv2 - offset; - var top = widthdiv2; - var bottom = - widthdiv2; - camera.frustum = new PerspectiveOffCenterFrustum({ - left: left, - right: right, - top: top, - bottom: bottom, - near: near, - far: far - }); + var left = -aspectRatio * widthOverTwo - offset; + var right = aspectRatio * widthOverTwo - offset; + var top = widthOverTwo; + var bottom = -widthOverTwo; + + var vrFrustum = camera.frustum = scratchVRFrustum; + + vrFrustum.left = left; + vrFrustum.right = right; + vrFrustum.top = top; + vrFrustum.bottom = bottom; + vrFrustum.near = near; + vrFrustum.far = far; executeCommands(scene, passState); @@ -2709,18 +2711,17 @@ import View from './View.js'; Cartesian3.subtract(savedCamera.position, eyeTranslation, camera.position); - left = - aspectRatio * widthdiv2 + offset; - right = aspectRatio * widthdiv2 + offset; - top = widthdiv2; - bottom = - widthdiv2; - camera.frustum = new PerspectiveOffCenterFrustum({ - left: left, - right: right, - top: top, - bottom: bottom, - near: near, - far: far - }); + left = -aspectRatio * widthOverTwo + offset; + right = aspectRatio * widthOverTwo + offset; + top = widthOverTwo; + bottom = -widthOverTwo; + + vrFrustum.left = left; + vrFrustum.right = right; + vrFrustum.top = top; + vrFrustum.bottom = bottom; + vrFrustum.near = near; + vrFrustum.far = far; executeCommands(scene, passState);