Skip to content

Commit

Permalink
RVec3: add 6 public methods
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Feb 23, 2025
1 parent 2afcf89 commit 7036318
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions src/main/java/com/github/stephengold/joltjni/RVec3.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ of this software and associated documentation files (the "Software"), to deal
*/
package com.github.stephengold.joltjni;

import com.github.stephengold.joltjni.operator.Op;
import com.github.stephengold.joltjni.readonly.RVec3Arg;
import com.github.stephengold.joltjni.readonly.Vec3Arg;

Expand Down Expand Up @@ -137,6 +138,49 @@ public boolean isFinite() {
}
}

/**
* Create a unit vector along the 1st (X) principal axis.
*
* @return a new vector
*/
public static RVec3 sAxisX() {
RVec3 result = new RVec3(1., 0., 0.);
return result;
}

/**
* Create a unit vector along the 2nd (Y) principal axis.
*
* @return a new vector
*/
public static RVec3 sAxisY() {
RVec3 result = new RVec3(0., 1., 0.);
return result;
}

/**
* Create a unit vector along the 3rd (Z) principal axis.
*
* @return a new vector
*/
public static RVec3 sAxisZ() {
RVec3 result = new RVec3(0., 0., 1.);
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(double xScale, double yScale, double zScale) {
this.xx *= xScale;
this.yy *= yScale;
this.zz *= zScale;
}

/**
* Set all 3 components to specified values.
*
Expand All @@ -162,6 +206,17 @@ public void set(double[] array) {
this.zz = array[2];
}

/**
* Set all 3 components from the argument.
*
* @param source the vector to copy (not null, unaffected)
*/
public void set(RVec3Arg source) {
this.xx = source.xx();
this.yy = source.yy();
this.zz = source.zz();
}

/**
* Alter the first (X) component.
*
Expand Down Expand Up @@ -206,6 +261,21 @@ public static RVec3 sReplicate(double value) {
return result;
}

/**
* Return the component-wise sum of the specified vectors.
*
* @param vArray an array of input vectors (not null, unaffected)
* @return a new vector
*/
public static RVec3 sum(RVec3Arg... vArray) {
RVec3 result = new RVec3();
for (RVec3Arg arg : vArray) {
Op.plusEquals(result, arg);
}

return result;
}

/**
* Create a vector with all components zero.
*
Expand Down

0 comments on commit 7036318

Please sign in to comment.