Skip to content

Commit

Permalink
Vec3Arg: add the swizzle() method
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Nov 24, 2024
1 parent 3f4ec7f commit 21c37ee
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/main/java/com/github/stephengold/joltjni/Vec3.java
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,28 @@ public void storeFloat3(Float3 target) {
target.z = z;
}

/**
* Copy the specified components to a new vector. The current vector is
* unaffected.
*
* @param xi index of the component to copy to the first (X) component of
* the result (0, 1, or 2)
* @param yi index of the component to copy to the 2nd (Y) component of the
* result (0, 1, or 2)
* @param zi index of the component to copy to the 3rd (Z) component of the
* result (0, 1, or 2)
* @return the new vector
*/
@Override
public Vec3 swizzle(int xi, int yi, int zi) {
float rx = get(xi);
float ry = get(yi);
float rz = get(zi);
Vec3 result = new Vec3(rx, ry, rz);

return result;
}

/**
* Copy the components to an array. The vector is unaffected.
*
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/com/github/stephengold/joltjni/readonly/Vec3Arg.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,20 @@ public interface Vec3Arg {
*/
void storeFloat3(Float3 target);

/**
* Copy the specified components to a new vector. The current vector is
* unaffected.
*
* @param xi index of the component to copy to the first (X) component of
* the result (0, 1, or 2)
* @param yi index of the component to copy to the 2nd (Y) component of the
* result (0, 1, or 2)
* @param zi index of the component to copy to the 3rd (Z) component of the
* result (0, 1, or 2)
* @return the new vector
*/
Vec3 swizzle(int xi, int yi, int zi);

/**
* Copy the components to an array. The vector is unaffected.
*
Expand Down

0 comments on commit 21c37ee

Please sign in to comment.