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 e5b2c6c6a879..0584473c9caf 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -244,6 +244,7 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to Cesiu * [Tinco Andringa](https://github.com/tinco) * [André Borud](https://github.com/andreborud) * [Nathan Schulte](https://github.com/nmschulte) +* [SorryNotSorryBasileus](https://github.com/SorryNotSorryBasileus) * [Ricardo Morin](https://github.com/jimmyangel) * [Jan Wąsak](https://github.com/jhnwsk) * [Julian Fell](https://github.com/jtfell) 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 681b037e435c..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; @@ -2678,23 +2680,48 @@ import View from './View.js'; 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 widthOverTwo = near * Math.tan(camera.frustum.fov / 2.0); var offset = 0.5 * eyeSeparation * near / fo; Cartesian3.add(savedCamera.position, eyeTranslation, camera.position); - camera.frustum.xOffset = offset; + + 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); viewport.x = viewport.width; Cartesian3.subtract(savedCamera.position, eyeTranslation, camera.position); - camera.frustum.xOffset = -offset; + + 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);