diff --git a/src/main/java/com/github/stephengold/joltjni/Vec3.java b/src/main/java/com/github/stephengold/joltjni/Vec3.java index ac99ec52..4bcc0df0 100644 --- a/src/main/java/com/github/stephengold/joltjni/Vec3.java +++ b/src/main/java/com/github/stephengold/joltjni/Vec3.java @@ -142,6 +142,29 @@ public Vec3(Vec3Arg vec) { // ************************************************************************* // new methods exposed + /** + * Add the specified offsets. + * + * @param xOffset the amount to add to the X component + * @param yOffset the amount to add to the Y component + * @param zOffset the amount to add to the Z component + */ + public void addInPlace(float xOffset, float yOffset, float zOffset) { + this.x += xOffset; + this.y += yOffset; + this.z += zOffset; + } + + /** + * Change the current vector to a unit vector with the same direction. + */ + public void normalizeInPlace() { + float invLength = 1f / length(); + this.x *= invLength; + this.y *= invLength; + this.z *= invLength; + } + /** * Return the bitwise AND of the specified vectors. * @@ -196,6 +219,19 @@ public static Vec3 sAxisZ() { return result; } + /** + * Separately scale each component. + * + * @param xScale the scale factor to apply to the X component + * @param yScale the scale factor to apply to the Y component + * @param zScale the scale factor to apply to the Z component + */ + public void scaleInPlace(float xScale, float yScale, float zScale) { + this.x *= xScale; + this.y *= yScale; + this.z *= zScale; + } + /** * Set all 3 components to specified values. * @@ -221,6 +257,17 @@ public void set(float[] array) { this.z = array[2]; } + /** + * Set all 3 components from the argument. + * + * @param source the vector to copy (not null, unaffected) + */ + public void set(Vec3Arg source) { + this.x = source.getX(); + this.y = source.getY(); + this.z = source.getZ(); + } + /** * Alter the first (X) component. * @@ -403,6 +450,21 @@ public static Vec3 sSelect(Vec3Arg notSet, Vec3Arg set, UVec4Arg control) { return result; } + /** + * Replace any -0 elements with +0, in preparation for hashing. + */ + public void standardizeInPlace() { + if (Float.compare(x, -0f) == 0) { + this.x = 0f; + } + if (Float.compare(y, -0f) == 0) { + this.y = 0f; + } + if (Float.compare(z, -0f) == 0) { + this.z = 0f; + } + } + /** * Return the component-wise sum of the specified vectors. *