Skip to content

Commit

Permalink
Vec3: add 2 static add() methods
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Sep 20, 2024
1 parent c9cff5b commit 4016e6c
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/main/java/com/github/stephengold/joltjni/Vec3.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,39 @@ public Vec3(float[] array) {
// *************************************************************************
// new methods exposed

/**
* Return the component-wise sum of the specified vectors.
*
* @param v1 the first vector (not null, unaffected)
* @param v2 the 2nd vector (not null, unaffected)
* @return a new vector
*/
public static Vec3 add(Vec3Arg v1, Vec3Arg v2) {
float x = v1.getX() + v2.getX();
float y = v1.getY() + v2.getY();
float z = v1.getZ() + v2.getZ();
Vec3 result = new Vec3(x, y, z);

return result;
}

/**
* Return the component-wise sum of the specified vectors.
*
* @param v1 the first vector (not null, unaffected)
* @param v2 the 2nd vector (not null, unaffected)
* @param v3 the 3nd vector (not null, unaffected)
* @return a new vector
*/
public static Vec3 add(Vec3Arg v1, Vec3Arg v2, Vec3Arg v3) {
float x = v1.getX() + v2.getX() + v3.getX();
float y = v1.getY() + v2.getY() + v3.getY();
float z = v1.getZ() + v2.getZ() + v3.getZ();
Vec3 result = new Vec3(x, y, z);

return result;
}

/**
* Return a scaled version of the specified vector.
*
Expand Down

0 comments on commit 4016e6c

Please sign in to comment.