Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed image splitting in VR mode #8138

Closed
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion Source/Scene/Camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
35 changes: 31 additions & 4 deletions Source/Scene/Scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down