Skip to content

Commit

Permalink
RMat44Arg: add 7 methods
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Feb 23, 2025
1 parent aa40a17 commit 4ca469a
Show file tree
Hide file tree
Showing 3 changed files with 206 additions and 1 deletion.
91 changes: 91 additions & 0 deletions src/main/java/com/github/stephengold/joltjni/RMat44.java
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,22 @@ public Vec3 getAxisZ() {
return result;
}

/**
* Copy the diagonal elements to a {@code Vec3}. The matrix is unaffected.
*
* @return a new vector
*/
@Override
public Vec3 getDiagonal3() {
long matrixVa = va();
float x = (float) getElement(matrixVa, 0, 0);
float y = (float) getElement(matrixVa, 1, 1);
float z = (float) getElement(matrixVa, 2, 2);
Vec3 result = new Vec3(x, y, z);

return result;
}

/**
* Return the specified element in double precision. The matrix is
* unaffected.
Expand Down Expand Up @@ -328,13 +344,28 @@ public RMat44 inversed() {
return result;
}

/**
* Return the inverse of the 3x3 portion. The current matrix is unaffected.
*
* @return a new matrix
*/
@Override
public RMat44 inversed3x3() {
long currentVa = va();
long resultVa = inversed3x3(currentVa);
RMat44 result = new RMat44(resultVa, true);

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
*/
@Override
public RMat44 inversedRotationTranslation() {
long currentVa = va();
long resultVa = inversedRotationTranslation(currentVa);
Expand All @@ -359,6 +390,20 @@ public boolean isEqual(RMat44Arg m2) {
return result;
}

/**
* Test whether the current matrix is an identity matrix. The matrix is
* unaffected.
*
* @return {@code true} if exactly equal, otherwise {@code false}
*/
@Override
public boolean isIdentity() {
long matrixVa = va();
boolean result = isIdentity(matrixVa);

return result;
}

/**
* Multiply the current matrix by the argument. The current matrix is
* unaffected.
Expand All @@ -376,6 +421,23 @@ public RMat44 multiply(RMat44Arg right) {
return result;
}

/**
* Multiply the current 3x3 matrix by the specified 3x3 matrix. The current
* matrix is unaffected.
*
* @param right the right factor (not null, unaffected)
* @return a new matrix
*/
@Override
public RMat44 multiply3x3(RMat44Arg right) {
long leftVa = va();
long rightVa = right.targetVa();
long productVa = multiply3x3(leftVa, rightVa);
RMat44 result = new RMat44(productVa, true);

return result;
}

/**
* Multiply the 3x3 matrix by the specified column vector. The matrix is
* unaffected.
Expand Down Expand Up @@ -449,12 +511,32 @@ public RVec3 multiply3x4(Vec3Arg vec3) {
return result;
}

/**
* Post multiply by the specified translation vector. The current matrix is
* unaffected.
*
* @param rvec3 the left factor (not null, unaffected)
* @return a new matrix
*/
@Override
public RMat44 postTranslated(RVec3Arg rvec3) {
long matrixVa = va();
double xx = rvec3.xx();
double yy = rvec3.yy();
double zz = rvec3.zz();
long resultVa = postTranslated(matrixVa, xx, yy, zz);
RMat44 result = new RMat44(resultVa, true);

return result;
}

/**
* Copy the current matrix to a new, single-precision matrix. The current
* matrix is unaffected.
*
* @return the new matrix
*/
@Override
public Mat44 toMat44() {
Mat44 result = new Mat44(this);
return result;
Expand Down Expand Up @@ -535,12 +617,18 @@ native private static void getQuaternion(

native private static long inversed(long currentVa);

native private static long inversed3x3(long currentVa);

native private static long inversedRotationTranslation(long currentVa);

native private static boolean isIdentity(long matrixVa);

native private static long multiply(long leftVa, long rightVa);

native private static void multiply3x3(long matrixVa, float[] tmpFloats);

native private static long multiply3x3(long leftVa, long rightVa);

native private static void multiply3x3Transposed(
long matrixVa, float[] tmpFloats);

Expand All @@ -549,6 +637,9 @@ native private static void multiply3x4(

native private static void multiply3x4r(long matrixVa, double[] tmpDoubles);

native private static long postTranslated(
long matrixVa, double xx, double yy, double zz);

native private static void setElement(
long matrixVa, int row, int column, double value);

Expand Down
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.readonly;

import com.github.stephengold.joltjni.Mat44;
import com.github.stephengold.joltjni.Quat;
import com.github.stephengold.joltjni.RMat44;
import com.github.stephengold.joltjni.RVec3;
Expand Down Expand Up @@ -56,6 +57,13 @@ public interface RMat44Arg extends ConstJoltPhysicsObject {
*/
Vec3 getAxisZ();

/**
* Copy the diagonal elements to a {@code Vec3}. The matrix is unaffected.
*
* @return a new vector
*/
Vec3 getDiagonal3();

/**
* Return the specified element in double precision. The matrix is
* unaffected.
Expand Down Expand Up @@ -87,6 +95,22 @@ public interface RMat44Arg extends ConstJoltPhysicsObject {
*/
RMat44 inversed();

/**
* Return the inverse of the 3x3 portion. The current matrix is unaffected.
*
* @return a new matrix
*/
RMat44 inversed3x3();

/**
* 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
*/
RMat44 inversedRotationTranslation();

/**
* Test whether the current matrix is equal to the argument. The current
* matrix is unaffected.
Expand All @@ -96,6 +120,14 @@ public interface RMat44Arg extends ConstJoltPhysicsObject {
*/
boolean isEqual(RMat44Arg m2);

/**
* Test whether the current matrix is an identity matrix. The matrix is
* unaffected.
*
* @return {@code true} if exactly equal, otherwise {@code false}
*/
boolean isIdentity();

/**
* Multiply the current matrix by the argument. The current matrix is
* unaffected.
Expand All @@ -105,6 +137,15 @@ public interface RMat44Arg extends ConstJoltPhysicsObject {
*/
RMat44 multiply(RMat44Arg right);

/**
* Multiply the current 3x3 matrix by the specified 3x3 matrix. The current
* matrix is unaffected.
*
* @param right the right factor (not null, unaffected)
* @return a new matrix
*/
RMat44 multiply3x3(RMat44Arg right);

/**
* Multiply the 3x3 matrix by the specified column vector. The matrix is
* unaffected.
Expand Down Expand Up @@ -142,4 +183,21 @@ public interface RMat44Arg extends ConstJoltPhysicsObject {
* @return a new vector
*/
RVec3 multiply3x4(Vec3Arg vec3);

/**
* Post multiply by the specified translation vector. The current matrix is
* unaffected.
*
* @param rvec3 the left factor (not null, unaffected)
* @return a new matrix
*/
RMat44 postTranslated(RVec3Arg rvec3);

/**
* Copy the current matrix to a new, single-precision matrix. The current
* matrix is unaffected.
*
* @return the new matrix
*/
Mat44 toMat44();
}
58 changes: 57 additions & 1 deletion src/main/native/glue/r/RMat44.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,20 @@ JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_RMat44_inversed
return reinterpret_cast<jlong> (pResult);
}

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

/*
* Class: com_github_stephengold_joltjni_RMat44
* Method: inversedRotationTranslation
Expand All @@ -284,6 +298,18 @@ JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_RMat44_inversedRotat
return reinterpret_cast<jlong> (pResult);
}

/*
* Class: com_github_stephengold_joltjni_RMat44
* Method: isIdentity
* Signature: (J)Z
*/
JNIEXPORT jboolean JNICALL Java_com_github_stephengold_joltjni_RMat44_isIdentity
(JNIEnv *, jclass, jlong matrixVa) {
const RMat44 * const pMatrix = reinterpret_cast<RMat44 *> (matrixVa);
const bool result = (*pMatrix == RMat44::sIdentity());
return result;
}

/*
* Class: com_github_stephengold_joltjni_RMat44
* Method: multiply
Expand All @@ -304,7 +330,7 @@ JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_RMat44_multiply
* Method: multiply3x3
* Signature: (J[F)V
*/
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_RMat44_multiply3x3
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_RMat44_multiply3x3__J_3F
(JNIEnv *pEnv, jclass, jlong matrixVa, jfloatArray tmpFloats) {
const RMat44 * const pMatrix = reinterpret_cast<RMat44 *> (matrixVa);
jboolean isCopy;
Expand All @@ -318,6 +344,21 @@ JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_RMat44_multiply3x3
pEnv->ReleaseFloatArrayElements(tmpFloats, pTmpFloats, 0);
}

/*
* Class: com_github_stephengold_joltjni_RMat44
* Method: multiply3x3
* Signature: (JJ)J
*/
JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_RMat44_multiply3x3__JJ
(JNIEnv *, jclass, jlong leftVa, jlong rightVa) {
const RMat44 * const pLeft = reinterpret_cast<RMat44 *> (leftVa);
const RMat44 * const pRight = reinterpret_cast<RMat44 *> (rightVa);
RMat44 * const pResult = new RMat44();
TRACE_NEW("RMat44", pResult)
*pResult = pLeft->Multiply3x3(*pRight);
return reinterpret_cast<jlong> (pResult);
}

/*
* Class: com_github_stephengold_joltjni_RMat44
* Method: multiply3x3Transposed
Expand Down Expand Up @@ -374,6 +415,21 @@ JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_RMat44_multiply3x4r
pEnv->ReleaseDoubleArrayElements(tmpDoubles, pTmpDoubles, 0);
}

/*
* Class: com_github_stephengold_joltjni_RMat44
* Method: postTranslated
* Signature: (JDDD)J
*/
JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_RMat44_postTranslated
(JNIEnv *, jclass, jlong matrixVa, jdouble xx, jdouble yy, jdouble zz) {
const RMat44 * const pMatrix = reinterpret_cast<RMat44 *> (matrixVa);
const RVec3 offset(xx, yy, zz);
RMat44 * const pResult = new RMat44();
TRACE_NEW("RMat44", pResult)
*pResult = pMatrix->PostTranslated(offset);
return reinterpret_cast<jlong> (pResult);
}

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

0 comments on commit 4ca469a

Please sign in to comment.