Browse Source

Merge pull request #8952 from RaananW/projectionMatrixXR

[XR] main camera's projection matrix
David Catuhe 5 years ago
parent
commit
503024c37a
2 changed files with 10 additions and 2 deletions
  1. 1 0
      dist/preview release/what's new.md
  2. 9 2
      src/XR/webXRCamera.ts

+ 1 - 0
dist/preview release/what's new.md

@@ -197,6 +197,7 @@
 - WebXR hand-tracking module is available, able to track hand-joints on selected devices including optional physics interactions ([RaananW](https://github.com/RaananW))
 - Fixed an issue with moving backwards in XR ([#8854](https://github.com/BabylonJS/Babylon.js/issues/8854)) ([RaananW](https://github.com/RaananW))
 - Hit-Test results can be an empty array ([#8887](https://github.com/BabylonJS/Babylon.js/issues/8887)) ([RaananW](https://github.com/RaananW))
+- XR's main camera uses the first eye's projection matrix ([#8944](https://github.com/BabylonJS/Babylon.js/issues/8944)) ([RaananW](https://github.com/RaananW))
 
 ### Collisions
 

+ 9 - 2
src/XR/webXRCamera.ts

@@ -5,7 +5,7 @@ import { FreeCamera } from "../Cameras/freeCamera";
 import { TargetCamera } from "../Cameras/targetCamera";
 import { WebXRSessionManager } from "./webXRSessionManager";
 import { Viewport } from "../Maths/math.viewport";
-import { Observable } from '../Misc/observable';
+import { Observable } from "../Misc/observable";
 
 /**
  * WebXR Camera which holds the views for the xrSession
@@ -49,6 +49,8 @@ export class WebXRCamera extends FreeCamera {
         this.cameraRigMode = Camera.RIG_MODE_CUSTOM;
         this.updateUpVectorFromRotation = true;
         this._updateNumberOfRigCameras(1);
+        // freeze projection matrix, which will be copied later
+        this.freezeProjectionMatrix();
 
         this._xrSessionManager.onXRSessionInit.add(() => {
             this._referencedPosition.copyFromFloats(0, 0, 0);
@@ -167,7 +169,7 @@ export class WebXRCamera extends FreeCamera {
             this._updateNumberOfRigCameras(pose.views.length);
         }
 
-        pose.views.forEach((view: any, i: number) => {
+        pose.views.forEach((view: XRView, i: number) => {
             const currentRig = <TargetCamera>this.rigCameras[i];
             // update right and left, where applicable
             if (!currentRig.isLeftCamera && !currentRig.isRightCamera) {
@@ -196,6 +198,11 @@ export class WebXRCamera extends FreeCamera {
                 currentRig._projectionMatrix.toggleProjectionMatrixHandInPlace();
             }
 
+            // first camera?
+            if (i === 0) {
+                this._projectionMatrix.copyFrom(currentRig._projectionMatrix);
+            }
+
             // Update viewport
             if (this._xrSessionManager.session.renderState.baseLayer) {
                 var viewport = this._xrSessionManager.session.renderState.baseLayer.getViewport(view);