Browse Source

Fix pose transforms

Brian Peiris 7 years ago
parent
commit
0f452ef128
1 changed files with 25 additions and 12 deletions
  1. 25 12
      src/renderers/webvr/WebVRManager.js

+ 25 - 12
src/renderers/webvr/WebVRManager.js

@@ -4,6 +4,8 @@
 
 import { Matrix4 } from '../../math/Matrix4.js';
 import { Vector4 } from '../../math/Vector4.js';
+import { Vector3 } from '../../math/Vector3.js';
+import { Quaternion } from '../../math/Quaternion.js';
 import { ArrayCamera } from '../../cameras/ArrayCamera.js';
 import { PerspectiveCamera } from '../../cameras/PerspectiveCamera.js';
 
@@ -26,6 +28,8 @@ function WebVRManager( renderer ) {
 	}
 
 	var matrixWorldInverse = new Matrix4();
+	var tempQuaternion = new Quaternion();
+	var tempPosition = new Vector3();
 
 	var cameraL = new PerspectiveCamera();
 	cameraL.bounds = new Vector4( 0.0, 0.0, 0.5, 1.0 );
@@ -104,40 +108,49 @@ function WebVRManager( renderer ) {
 
 		//
 
-		var pose = frameData.pose;
-		var poseObject = poseTarget !== null ? poseTarget : camera;
+		var stageParameters = device.stageParameters;
 
-		if ( pose.position !== null ) {
+		if ( stageParameters ) {
 
-			poseObject.position.fromArray( pose.position );
+			standingMatrix.fromArray( stageParameters.sittingToStandingTransform );
 
 		} else {
 
-			poseObject.position.set( 0, 0, 0 );
+			standingMatrix.makeTranslation( 0, scope.userHeight, 0 );
 
 		}
 
+
+		var pose = frameData.pose;
+		var poseObject = poseTarget !== null ? poseTarget : camera;
+
+		// We want to manipulate poseObject by its position and quaternion components since users may rely on them.
+		poseObject.matrix.copy( standingMatrix );
+		poseObject.matrix.decompose(poseObject.position, poseObject.quaternion, poseObject.scale);
+
 		if ( pose.orientation !== null ) {
 
-			poseObject.quaternion.fromArray( pose.orientation );
+			tempQuaternion.fromArray ( pose.orientation );
+			poseObject.quaternion.multiply( tempQuaternion );
 
 		}
 
-		var stageParameters = device.stageParameters;
-
-		if ( stageParameters ) {
+		if ( pose.position !== null ) {
 
-			standingMatrix.fromArray( stageParameters.sittingToStandingTransform );
+			tempQuaternion.setFromRotationMatrix(standingMatrix);
+			tempPosition.fromArray( pose.position );
+			tempPosition.applyQuaternion(tempQuaternion);
+			poseObject.position.add( tempPosition );
 
 		} else {
 
-			standingMatrix.makeTranslation( 0, scope.userHeight, 0 );
+			poseObject.position.set( 0, 0, 0 );
 
 		}
 
-		poseObject.position.applyMatrix4( standingMatrix );
 		poseObject.updateMatrixWorld();
 
+
 		if ( device.isPresenting === false ) return camera;
 
 		//