浏览代码

Merge pull request #7527 from avin/missed_methods

Add missed negate-methods
David Catuhe 5 年之前
父节点
当前提交
4b4abc7992
共有 1 个文件被更改,包括 49 次插入0 次删除
  1. 49 0
      src/Maths/math.vector.ts

+ 49 - 0
src/Maths/math.vector.ts

@@ -257,6 +257,25 @@ export class Vector2 {
     }
 
     /**
+     * Negate this vector in place
+     * @returns this
+     */
+    public negateInPlace(): Vector2 {
+        this.x *= -1;
+        this.y *= -1;
+        return this;
+    }
+
+    /**
+     * Negate the current Vector2 and stores the result in the given vector "result" coordinates
+     * @param result defines the Vector3 object where to store the result
+     * @returns the current Vector2
+     */
+    public negateToRef(result: Vector2): Vector2 {
+        return result.copyFromFloats(this.x * -1, this.y * -1);
+    }
+
+    /**
      * Multiply the Vector2 coordinates by scale
      * @param scale defines the scaling factor
      * @returns the current updated Vector2
@@ -851,6 +870,15 @@ export class Vector3 {
     }
 
     /**
+     * Negate the current Vector3 and stores the result in the given vector "result" coordinates
+     * @param result defines the Vector3 object where to store the result
+     * @returns the current Vector3
+     */
+    public negateToRef(result: Vector3): Vector3 {
+        return result.copyFromFloats(this.x * -1, this.y * -1, this.z * -1);
+    }
+
+    /**
      * Multiplies the Vector3 coordinates by the float "scale"
      * @param scale defines the multiplier factor
      * @returns the current updated Vector3
@@ -2101,6 +2129,27 @@ export class Vector4 {
     }
 
     /**
+     * Negate this vector in place
+     * @returns this
+     */
+    public negateInPlace(): Vector4 {
+        this.x *= -1;
+        this.y *= -1;
+        this.z *= -1;
+        this.w *= -1;
+        return this;
+    }
+
+    /**
+     * Negate the current Vector4 and stores the result in the given vector "result" coordinates
+     * @param result defines the Vector3 object where to store the result
+     * @returns the current Vector4
+     */
+    public negateToRef(result: Vector4): Vector4 {
+        return result.copyFromFloats(this.x * -1, this.y * -1, this.z * -1, this.w * -1);
+    }
+
+    /**
      * Multiplies the current Vector4 coordinates by scale (float).
      * @param scale the number to scale with
      * @returns the updated Vector4.