浏览代码

Merge pull request #8445 from RaananW/rigXRFix

[XR] View Matrix calculations
sebavan 5 年之前
父节点
当前提交
5ee32afcd2
共有 1 个文件被更改,包括 8 次插入14 次删除
  1. 8 14
      src/XR/webXRCamera.ts

+ 8 - 14
src/XR/webXRCamera.ts

@@ -118,6 +118,8 @@ export class WebXRCamera extends FreeCamera {
         return this._computedViewMatrix;
     }
 
+    private _rotate180 = new Quaternion(0, 1, 0, 0);
+
     private _updateFromXRSession() {
         const pose = this._xrSessionManager.currentFrame && this._xrSessionManager.currentFrame.getViewerPose(this._xrSessionManager.referenceSpace);
 
@@ -179,21 +181,17 @@ export class WebXRCamera extends FreeCamera {
                 }
             }
             // Update view/projection matrix
-            currentRig.position.copyFrom(view.transform.position);
-            currentRig.rotationQuaternion.copyFrom(view.transform.orientation);
+            const pos = view.transform.position;
+            const orientation = view.transform.orientation;
+
+            currentRig.position.set(pos.x, pos.y, pos.z);
+            currentRig.rotationQuaternion.set(orientation.x, orientation.y, orientation.z, orientation.w);
             if (!this._scene.useRightHandedSystem) {
                 currentRig.position.z *= -1;
                 currentRig.rotationQuaternion.z *= -1;
                 currentRig.rotationQuaternion.w *= -1;
-            }
-            if (view.transform.inverse) {
-                Matrix.FromFloat32ArrayToRefScaled(view.transform.inverse.matrix, 0, 1, currentRig._computedViewMatrix);
             } else {
-                Matrix.FromFloat32ArrayToRefScaled(view.transform.matrix, 0, 1, currentRig._computedViewMatrix);
-                currentRig._computedViewMatrix.invert();
-            }
-            if (!this._scene.useRightHandedSystem) {
-                currentRig._computedViewMatrix.toggleModelMatrixHandInPlace();
+                currentRig.rotationQuaternion.multiplyInPlace(this._rotate180);
             }
             Matrix.FromFloat32ArrayToRefScaled(view.projectionMatrix, 0, 1, currentRig._projectionMatrix);
 
@@ -227,10 +225,6 @@ export class WebXRCamera extends FreeCamera {
             newCamera.rigParent = this;
             // do not compute projection matrix, provided by XR
             newCamera.freezeProjectionMatrix();
-            // use the view matrix provided by XR
-            newCamera._getViewMatrix = function(): Matrix {
-                return this._computedViewMatrix;
-            };
             this.rigCameras.push(newCamera);
         }
         while (this.rigCameras.length > viewCount) {