Jelajahi Sumber

Merge pull request #392 from jahow/pr-engine-resize

Added FOV mode setting to engine
David Catuhe 10 tahun lalu
induk
melakukan
1ba0e39c52
2 mengubah file dengan 16 tambahan dan 4 penghapusan
  1. 5 1
      Babylon/Cameras/babylon.camera.ts
  2. 11 3
      Babylon/Math/babylon.math.ts

+ 5 - 1
Babylon/Cameras/babylon.camera.ts

@@ -4,6 +4,9 @@
         public static PERSPECTIVE_CAMERA = 0;
         public static ORTHOGRAPHIC_CAMERA = 1;
 
+        private static FOVMODE_VERTICAL_FIXED = 0;
+        private static FOVMODE_HORIZONTAL_FIXED = 1;
+
         // Members
         public upVector = Vector3.Up();
         public orthoLeft = null;
@@ -19,6 +22,7 @@
         public viewport = new Viewport(0, 0, 1.0, 1.0);
         public subCameras = [];
         public layerMask: number = 0xFFFFFFFF;
+        public fovMode: number = Camera.FOVMODE_VERTICAL_FIXED;
 
         private _computedViewMatrix = Matrix.Identity();
         public _projectionMatrix = new Matrix();
@@ -291,7 +295,7 @@
                     this.minZ = 0.1;
                 }
 
-                Matrix.PerspectiveFovLHToRef(this.fov, engine.getAspectRatio(this), this.minZ, this.maxZ, this._projectionMatrix);
+                Matrix.PerspectiveFovLHToRef(this.fov, engine.getAspectRatio(this), this.minZ, this.maxZ, this._projectionMatrix, this.fovMode);
                 return this._projectionMatrix;
             }
 

+ 11 - 3
Babylon/Math/babylon.math.ts

@@ -2075,12 +2075,20 @@
             return matrix;
         }
 
-        public static PerspectiveFovLHToRef(fov: number, aspect: number, znear: number, zfar: number, result: Matrix): void {
+        public static PerspectiveFovLHToRef(fov: number, aspect: number, znear: number, zfar: number, result: Matrix, fovMode?: number): void {
             var tan = 1.0 / (Math.tan(fov * 0.5));
 
-            result.m[0] = tan / aspect;
+            var v_fixed = !fovMode || (fovMode == Camera.FOVMODE_VERTICAL_FIXED);
+            var h_fixed = (fovMode == Camera.FOVMODE_HORIZONTAL_FIXED);
+
+            if(v_fixed) { result.m[0] = tan / aspect; }
+            else if(h_fixed) { result.m[0] = tan; }  
+
             result.m[1] = result.m[2] = result.m[3] = 0.0;
-            result.m[5] = tan;
+
+            if(v_fixed) { result.m[5] = tan; }
+            else if(h_fixed) { result.m[5] = tan * aspect; }
+
             result.m[4] = result.m[6] = result.m[7] = 0.0;
             result.m[8] = result.m[9] = 0.0;
             result.m[10] = -zfar / (znear - zfar);