Explorar o código

added 'fovMode' setting on engine

- a new 'fovMode' public property has been added on the engine
- two new static constants have been added to the Engine class:
  FOVMODE_VERTICAL_FIXED (default)
  FOVMODE_HORIZONTAL_FIXED
- a new optional parameter has been added to the PerspectiveFovLHToRef
  function of the Matrix class, allowing to change the FOV mode
- the Camera class has been modified, so that when it calls
  PerspectiveFovLHToRef to create its projection matrix, it will pass the
  current engine fovMode property to it
- FOV mode can be effectively changed at runtime, since the camera's
  projection matrix will be recreated with the newest FOV mode at each resize
- since the property can take different values, it is possible to add new
  FOV modes, for example: anamorphic, stretch, etc.
olivier.g %!s(int64=10) %!d(string=hai) anos
pai
achega
06d2fa8f89

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

@@ -291,7 +291,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, engine.fovMode);
                 return this._projectionMatrix;
             }
 

+ 12 - 1
Babylon/Math/babylon.math.ts

@@ -2075,9 +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));
 
+            var v_fixed = !fovMode || (fovMode == BABYLON.Engine.FOVMODE_VERTICAL_FIXED);
+            var h_fixed = (fovMode == BABYLON.Engine.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;
+
+            if(v_fixed) { result.m[5] = tan; }
+            else if(h_fixed) { result.m[5] = tan * aspect; }
+
             result.m[0] = tan / aspect;
             result.m[1] = result.m[2] = result.m[3] = 0.0;
             result.m[5] = tan;

+ 4 - 0
Babylon/babylon.engine.ts

@@ -365,6 +365,9 @@
         private static _DELAYLOADSTATE_LOADING = 2;
         private static _DELAYLOADSTATE_NOTLOADED = 4;
 
+        private static _FOVMODE_VERTICAL_FIXED = 0;
+        private static _FOVMODE_HORIZONTAL_FIXED = 1;
+
         private static _TEXTUREFORMAT_ALPHA = 0;
         private static _TEXTUREFORMAT_LUMINANCE = 1;
         private static _TEXTUREFORMAT_LUMINANCE_ALPHA = 2;
@@ -445,6 +448,7 @@
         public cullBackFaces = true;
         public renderEvenInBackground = true;
         public scenes = new Array<Scene>();
+        public fovMode = Engine.FOVMODE_VERTICAL_FIXED;
 
         // Private Members
         public _gl: WebGLRenderingContext;