Преглед на файлове

Added some utility functions to Vector2 / 3 / 4

Hi, I felt adding these functions would be consistent with the other ones and they are useful for producing clearer and more compact code.
jahow преди 10 години
родител
ревизия
365ca1b246
променени са 1 файла, в които са добавени 45 реда и са изтрити 1 реда
  1. 45 1
      Babylon/Math/babylon.math.ts

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

@@ -295,6 +295,13 @@
             return new Vector2(this.x + otherVector.x, this.y + otherVector.y);
         }
 
+        public addInPlace(otherVector: Vector2): Vector2 {
+            this.x += otherVector.x;
+            this.y += otherVector.y;
+
+            return this;
+        }
+
         public subtract(otherVector: Vector2): Vector2 {
             return new Vector2(this.x - otherVector.x, this.y - otherVector.y);
         }
@@ -339,6 +346,10 @@
             return this;
         }
 
+        public divideByFloats(x: number, y: number): Vector2 {
+            return new Vector2(this.x / x, this.y / y);
+        }
+
         public negate(): Vector2 {
             return new Vector2(-this.x, -this.y);
         }
@@ -559,6 +570,18 @@
             return this;
         }
 
+        public addFromFloats(x: number, y: number, z: number): Vector3 {
+            return new Vector3(this.x + x, this.y + y, this.z + z);
+        }
+
+        public addFromFloatsToRef(x: number, y: number, z: number, result: Vector3): Vector3 {
+            result.x = this.x + x;
+            result.y = this.y + y;
+            result.z = this.z + z;
+
+            return this;
+        }
+
         public subtractInPlace(otherVector: Vector3): Vector3 {
             this.x -= otherVector.x;
             this.y -= otherVector.y;
@@ -660,6 +683,10 @@
             return this;
         }
 
+        public divideByFloats(x: number, y: number, z: number): Vector3 {
+            return new Vector3(this.x / x, this.y / y, this.z / z);
+        }
+
         public MinimizeInPlace(other: Vector3): Vector3 {
             if (other.x < this.x) this.x = other.x;
             if (other.y < this.y) this.y = other.y;
@@ -1170,6 +1197,19 @@
             return this;
         }
 
+        public addFromFloats(x: number, y: number, z: number, w: number): Vector4 {
+            return new Vector4(this.x + x, this.y + y, this.z + z, this.w + w);
+        }
+
+        public addFromFloatsToRef(x: number, y: number, z: number, w: number, result: Vector4): Vector4 {
+            result.x = this.x + x;
+            result.y = this.y + y;
+            result.z = this.z + z;
+            result.w = this.w + w;
+
+            return this;
+        }
+
         public subtractInPlace(otherVector: Vector4): Vector4 {
             this.x -= otherVector.x;
             this.y -= otherVector.y;
@@ -1283,6 +1323,10 @@
             return this;
         }
 
+        public divideByFloats(x: number, y: number, z: number, w: number): Vector4 {
+            return new Vector4(this.x / x, this.y / y, this.z / z, this.w / w);
+        }
+
         public MinimizeInPlace(other: Vector4): Vector4 {
             if (other.x < this.x) this.x = other.x;
             if (other.y < this.y) this.y = other.y;
@@ -3699,4 +3743,4 @@
             SIMDHelper._isEnabled = true;
         }
     }
-}
+}