Raanan Weber 8 anni fa
parent
commit
a1d13e2f58
1 ha cambiato i file con 22 aggiunte e 36 eliminazioni
  1. 22 36
      src/Cameras/babylon.camera.ts

+ 22 - 36
src/Cameras/babylon.camera.ts

@@ -598,28 +598,27 @@
                     break;
                 case Camera.RIG_MODE_WEBVR:
                     if (rigParams.vrDisplay) {
-                        var leftEye = rigParams.vrDisplay.getEyeParameters('left');
-                        var rightEye = rigParams.vrDisplay.getEyeParameters('right');
+                        //var leftEye = rigParams.vrDisplay.getEyeParameters('left');
+                        //var rightEye = rigParams.vrDisplay.getEyeParameters('right');
+
+                        //Left eye
                         this._rigCameras[0].viewport = new Viewport(0, 0, 0.5, 1.0);
                         this._rigCameras[0].setCameraRigParameter("left", true);
                         this._rigCameras[0].setCameraRigParameter("frameData", rigParams.frameData);
-                        this._rigCameras[0].setCameraRigParameter('eyeParameters', leftEye);
-                        //this._rigCameras[0].setCameraRigParameter("vrOffsetMatrix", Matrix.Translation(-leftEye.offset[0], leftEye.offset[1], -leftEye.offset[2]));
+                        this._rigCameras[0].setCameraRigParameter("parentCamera", rigParams.parentCamera);
+                        //this._rigCameras[0].setCameraRigParameter('eyeParameters', leftEye);
                         this._rigCameras[0]._cameraRigParams.vrWorkMatrix = new Matrix();
                         this._rigCameras[0].getProjectionMatrix = this._getWebVRProjectionMatrix;
-                        this._rigCameras[0]._getViewMatrix = this._getWebVRViewMatrix;
-                        //this._rigCameras[0]._cameraRigParams.vrPreViewMatrix = Matrix.Translation(-leftEye.offset[0], leftEye.offset[1], leftEye.offset[2]);
-                        //this._rigCameras[0]._cameraRigParams.getViewMatrix = this._getViewMatrix;
+                        this._rigCameras[0].getViewMatrix = this._getWebVRViewMatrix;
+
+                        //Right eye
                         this._rigCameras[1].viewport = new Viewport(0.5, 0, 0.5, 1.0);
-                        this._rigCameras[1].setCameraRigParameter('eyeParameters', rightEye);
+                        //this._rigCameras[1].setCameraRigParameter('eyeParameters', rightEye);
                         this._rigCameras[1].setCameraRigParameter("frameData", rigParams.frameData);
-                        //this._rigCameras[1].setCameraRigParameter("vrOffsetMatrix", Matrix.Translation(-rightEye.offset[0], rightEye.offset[1], -rightEye.offset[2]));
+                        this._rigCameras[1].setCameraRigParameter("parentCamera", rigParams.parentCamera);
                         this._rigCameras[1]._cameraRigParams.vrWorkMatrix = new Matrix();
                         this._rigCameras[1].getProjectionMatrix = this._getWebVRProjectionMatrix;
-                        this._rigCameras[1]._getViewMatrix = this._getWebVRViewMatrix;
-                        //this._rigCameras[1]._cameraRigParams.vrPreViewMatrix = Matrix.Translation(-rightEye.offset[0], rightEye.offset[1], rightEye.offset[2]);
-                        //this._rigCameras[1]._cameraRigParams.getViewMatrix = this._getViewMatrix;
-
+                        this._rigCameras[1].getViewMatrix = this._getWebVRViewMatrix;
                     }
                     break;
 
@@ -636,32 +635,19 @@
             return this._projectionMatrix;
         }
 
-        private _getWebVRProjectionMatrix(): Matrix {
-            var projectionArray = this._cameraRigParams["left"] ? this._cameraRigParams["frameData"].leftProjectionMatrix : this._cameraRigParams["frameData"].rightProjectionMatrix;
-            //babylon compatible matrix
-            if (!this.getScene().useRightHandedSystem) {
-                [8, 9, 10, 11].forEach(function (num) {
-                    projectionArray[num] *= -1;
-                });
-            }
-            Matrix.FromArrayToRef(projectionArray, 0, this._projectionMatrix);
-            //var eyeParams = this._cameraRigParams['eyeParameters'];
-            //Matrix.PerspectiveFovWebVRToRef(eyeParams.fieldOfView, this.minZ, this.maxZ, this._projectionMatrix, this.getScene().useRightHandedSystem)
-            return this._projectionMatrix;
+        /**
+         * This function MUST be overwritten by the different WebVR cameras available.
+         * The context in which it is running is the RIG camera. So 'this' is the TargetCamera, left or right.
+         */
+        protected _getWebVRProjectionMatrix(): Matrix {
+            return Matrix.Identity();
         }
 
-        //Can be used, but we'll use the free camera's view matrix calculation
+        /**
+         * This function MUST be overwritten by the different WebVR cameras available.
+         * The context in which it is running is the RIG camera. So 'this' is the TargetCamera, left or right.
+         */
         protected _getWebVRViewMatrix(): Matrix {
-            /*var viewArray = this._cameraRigParams["left"] ? this._cameraRigParams["frameData"].leftViewMatrix : this._cameraRigParams["frameData"].rightViewMatrix;
-
-            if (!this.getScene().useRightHandedSystem) {
-                [2, 6, 8, 9, 14].forEach(function (num) {
-                    viewArray[num] *= -1;
-                });
-            }
-            Matrix.FromArrayToRef(viewArray, 0, this._webvrViewMatrix);
-
-            return this._webvrViewMatrix;*/
             return Matrix.Identity();
         }