Skip to content

Commit

Permalink
RMat44: add a constructor and inverseRotationTranslation()
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Feb 20, 2025
1 parent cb3b0ee commit 1fe79df
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/main/java/com/github/stephengold/joltjni/RMat44.java
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,21 @@ public RMat44 inversed() {
return result;
}

/**
* Return the inverse of the current matrix, assuming the current matrix
* consists entirely of rotation and translation. The current matrix is
* unaffected.
*
* @return a new matrix
*/
public RMat44 inversedRotationTranslation() {
long currentVa = va();
long resultVa = inversedRotationTranslation(currentVa);
RMat44 result = new RMat44(resultVa, true);

return result;
}

/**
* Test whether the current matrix is equal to the argument. The current
* matrix is unaffected.
Expand Down Expand Up @@ -432,6 +447,17 @@ public RVec3 multiply3x4(Vec3Arg vec3Arg) {

return result;
}

/**
* Copy the current matrix to a new, single-precision matrix. The current
* matrix is unaffected.
*
* @return the new matrix
*/
public Mat44 toMat44() {
Mat44 result = new Mat44(this);
return result;
}
// *************************************************************************
// Object methods

Expand Down Expand Up @@ -505,6 +531,8 @@ native private static void getQuaternion(

native private static long inversed(long currentVa);

native private static long inversedRotationTranslation(long currentVa);

native private static long multiply(long m1Va, long m2Va);

native private static void multiply3x3(long matrixVa, float[] tmpFloats);
Expand Down
14 changes: 14 additions & 0 deletions src/main/native/glue/r/RMat44.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,20 @@ JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_RMat44_inversed
return reinterpret_cast<jlong> (pResult);
}

/*
* Class: com_github_stephengold_joltjni_RMat44
* Method: inversedRotationTranslation
* Signature: (J)J
*/
JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_RMat44_inversedRotationTranslation
(JNIEnv *, jclass, jlong currentVa) {
const RMat44 * const pCurrent = reinterpret_cast<RMat44 *> (currentVa);
RMat44 * const pResult = new RMat44();
TRACE_NEW("RMat44", pResult)
*pResult = pCurrent->InversedRotationTranslation();
return reinterpret_cast<jlong> (pResult);
}

/*
* Class: com_github_stephengold_joltjni_RMat44
* Method: multiply
Expand Down

0 comments on commit 1fe79df

Please sign in to comment.