Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add simple math methods to Vector3f #1744

Merged
merged 1 commit into from
Jan 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 43 additions & 1 deletion jme3-core/src/main/java/com/jme3/math/Vector3f.java
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,20 @@ public Vector3f mult(Vector3f vec) {
}
return mult(vec, null);
}


/**
* 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
* @return a new Vector3f
*/
public Vector3f mult(float x, float y, float z) {
return new Vector3f(this.x * x, this.y * y, this.z * z);
}

/**
* Multiplies component-wise with the specified vector and returns the
* product in a 3rd vector. If the argument is null, null is returned.
Expand Down Expand Up @@ -617,6 +630,22 @@ public Vector3f divideLocal(float scalar) {
z *= scalar;
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
* @return the (modified) current instance (for chaining)
*/
public Vector3f divideLocal(float x, float y, float z) {
this.x /= x;
this.y /= y;
this.z /= z;
return this;
}

/**
* Divides component-wise by the argument and returns the quotient as a new
Expand All @@ -629,6 +658,19 @@ public Vector3f divide(Vector3f divisor) {
return new Vector3f(x / divisor.x, y / divisor.y, z / divisor.z);
}

/**
* 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
* @return a new Vector3f
*/
public Vector3f divide(float x, float y, float z) {
return new Vector3f(this.x / x, this.y / y, this.z / z);
}

/**
* Divides component-wise by the argument and returns the (modified) current
* instance.
Expand Down