소스 검색

Add more simple math methods to Vector4f (#1755)

Ryan McDonough 3 년 전
부모
커밋
08d7ba9e4e
1개의 변경된 파일46개의 추가작업 그리고 0개의 파일을 삭제
  1. 46 0
      jme3-core/src/main/java/com/jme3/math/Vector4f.java

+ 46 - 0
jme3-core/src/main/java/com/jme3/math/Vector4f.java

@@ -422,6 +422,20 @@ public final class Vector4f implements Savable, Cloneable, java.io.Serializable
         product.w = w * scalar;
         return product;
     }
+    
+    /**
+     * Multiplies component-wise by the specified components and returns the 
+     * product as a new instance. The current instance is unaffected.
+     *
+     * @param x the scale factor for the X component
+     * @param y the scale factor for the Y component
+     * @param z the scale factor for the Z component
+     * @param w the scale factor for the W component
+     * @return a new Vector4f
+     */
+    public Vector4f mult(float x, float y, float z, float w) {
+        return new Vector4f(this.x * x, this.y * y, this.z * z, this.w * w);
+    }
 
     /**
      * <code>multLocal</code> multiplies this vector by a scalar internally,
@@ -576,6 +590,38 @@ public final class Vector4f implements Savable, Cloneable, java.io.Serializable
         w /= divisor.w;
         return this;
     }
+    
+    /**
+     * Divides component-wise by the specified components returns the (modified) 
+     * current instance.
+     *
+     * @param x the divisor for the X component
+     * @param y the divisor for the Y component
+     * @param z the divisor for the Z component
+     * @param w the divisor for the W component
+     * @return the (modified) current instance (for chaining)
+     */
+    public Vector4f divideLocal(float x, float y, float z, float w) {
+        this.x /= x;
+        this.y /= y;
+        this.z /= z;
+        this.w /= w;
+        return this;
+    } 
+   
+    /**
+     * Divides component-wise by the specified components and returns the quotient
+     * as a new instance. The current instance is unaffected.
+     *
+     * @param x the divisor for the X component
+     * @param y the divisor for the Y component
+     * @param z the divisor for the Z component
+     * @param w the divisor for the W component
+     * @return a new Vector4f
+     */
+    public Vector4f divide(float x, float y, float z, float w) {
+        return new Vector4f(this.x / x, this.y / y, this.z / z, this.w / w);
+    }
 
     /**
      * <code>negate</code> returns the negative of this vector. All values are