浏览代码

Math Tools Update

Add number value normalization and denormalization math tools
MackeyK24 8 年之前
父节点
当前提交
d2a3a3336c
共有 1 个文件被更改,包括 14 次插入0 次删除
  1. 14 0
      src/Math/babylon.math.ts

+ 14 - 0
src/Math/babylon.math.ts

@@ -68,6 +68,20 @@
         public static Repeat(value:number, length:number): number {
 			return value - Math.floor(value / length) * length;
         }
+
+        /**
+         * Normalize the value between 0.0 and 1.0 using min and max values
+         */
+        public static Normalize(value:number, min:number, max:number): number {
+            return (value - min) / (max - min);
+        }
+
+        /**
+         * Denormalize the value from 0.0 and 1.0 using min and max values
+         */
+        public static Denormalize(normalized:number, min:number, max:number): number {
+            return (normalized * (max - min) + min);
+        }
     }