Skip to content

Commit 2e7c04c

Browse files
tojimrdoob
authored andcommitted
Partial revert of some WebVR 1.1 changes (mrdoob#9709)
They didn't produce correct eye translations in all cases (specifically standing scenes.) This reverted version may not be 100% accurate on future hardware (if the eyes have a rotation component, for example) but it's correct on all current WebVR implementations. That's better than blatantly wrong in some cases. Use of the WebVR-provided projection matricies has been left in, since that was working correctly.
1 parent 743db1c commit 2e7c04c

File tree

1 file changed

+5
-51
lines changed

1 file changed

+5
-51
lines changed

examples/js/effects/VREffect.js

Lines changed: 5 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ THREE.VREffect = function ( renderer, onError ) {
1515
var eyeTranslationL = new THREE.Vector3();
1616
var eyeTranslationR = new THREE.Vector3();
1717
var renderRectL, renderRectR;
18-
var headMatrix = new THREE.Matrix4();
19-
var headToEyeMatrixL = new THREE.Matrix4();
20-
var headToEyeMatrixR = new THREE.Matrix4();
2118

2219
var frameData = null;
2320
if ( 'VRFrameData' in window ) {
@@ -292,6 +289,10 @@ THREE.VREffect = function ( renderer, onError ) {
292289
camera.matrixWorld.decompose( cameraL.position, cameraL.quaternion, cameraL.scale );
293290
camera.matrixWorld.decompose( cameraR.position, cameraR.quaternion, cameraR.scale );
294291

292+
var scale = this.scale;
293+
cameraL.translateOnAxis( eyeTranslationL, scale );
294+
cameraR.translateOnAxis( eyeTranslationR, scale );
295+
295296
if ( vrDisplay.getFrameData ) {
296297

297298
vrDisplay.depthNear = camera.near;
@@ -302,23 +303,12 @@ THREE.VREffect = function ( renderer, onError ) {
302303
cameraL.projectionMatrix.elements = frameData.leftProjectionMatrix;
303304
cameraR.projectionMatrix.elements = frameData.rightProjectionMatrix;
304305

305-
getHeadToEyeMatrices( frameData );
306-
307-
cameraL.updateMatrix();
308-
cameraL.applyMatrix( headToEyeMatrixL );
309-
310-
cameraR.updateMatrix();
311-
cameraR.applyMatrix( headToEyeMatrixR );
312-
313306
} else {
314307

315308
cameraL.projectionMatrix = fovToProjection( eyeParamsL.fieldOfView, true, camera.near, camera.far );
316309
cameraR.projectionMatrix = fovToProjection( eyeParamsR.fieldOfView, true, camera.near, camera.far );
317310

318-
var scale = this.scale;
319-
cameraL.translateOnAxis( eyeTranslationL, scale );
320-
cameraR.translateOnAxis( eyeTranslationR, scale );
321-
311+
322312
}
323313

324314
// render left eye
@@ -386,42 +376,6 @@ THREE.VREffect = function ( renderer, onError ) {
386376

387377
//
388378

389-
var poseOrientation = new THREE.Quaternion();
390-
var posePosition = new THREE.Vector3();
391-
392-
function getHeadToEyeMatrices( frameData ) {
393-
394-
// Compute the matrix for the position of the head based on the pose
395-
if ( frameData.pose.orientation ) {
396-
397-
poseOrientation.fromArray( frameData.pose.orientation );
398-
headMatrix.makeRotationFromQuaternion( poseOrientation );
399-
400-
} else {
401-
402-
headMatrix.identity();
403-
404-
}
405-
406-
if ( frameData.pose.position ) {
407-
408-
posePosition.fromArray( frameData.pose.position );
409-
headMatrix.setPosition( posePosition );
410-
411-
}
412-
413-
// Take the view matricies and multiply them by the head matrix, which
414-
// leaves only the head-to-eye transform.
415-
headToEyeMatrixL.fromArray( frameData.leftViewMatrix );
416-
headToEyeMatrixL.premultiply( headMatrix );
417-
headToEyeMatrixL.getInverse( headToEyeMatrixL );
418-
419-
headToEyeMatrixR.fromArray( frameData.rightViewMatrix );
420-
headToEyeMatrixR.premultiply( headMatrix );
421-
headToEyeMatrixR.getInverse( headToEyeMatrixR );
422-
423-
}
424-
425379
function fovToNDCScaleOffset( fov ) {
426380

427381
var pxscale = 2.0 / ( fov.leftTan + fov.rightTan );

0 commit comments

Comments
 (0)