Skip to content

Commit

Permalink
SkeletonPose: add 3 public methods
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Dec 6, 2024
1 parent 57c38b7 commit f92c831
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
44 changes: 44 additions & 0 deletions src/main/java/com/github/stephengold/joltjni/SkeletonPose.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.readonly.RMat44Arg;
import com.github.stephengold.joltjni.readonly.RVec3Arg;

/**
Expand Down Expand Up @@ -61,6 +62,44 @@ public void calculateJointMatrices() {
calculateJointMatrices(poseVa);
}

/**
* Convert the joint matrices to joint states.
*/
public void calculateJointStates() {
long poseVa = va();
calculateJointStates(poseVa);
}

/**
* Draw the current pose using the specified settings and renderer. The pose
* is unaffected.
*
* @param settings the desired settings (not null, unaffected)
* @param renderer the renderer to use (not null)
*/
public void draw(
SkeletonPoseDrawSettings settings, DebugRenderer renderer) {
draw(settings, renderer, RMat44.sIdentity());
}

/**
* Draw the current pose using the specified settings and renderer. The pose
* is unaffected.
*
* @param settings the desired settings (not null, unaffected)
* @param renderer the renderer to use (not null)
* @param transform the transform to apply (not null, unaffected,
* default=Identity)
*/
public void draw(SkeletonPoseDrawSettings settings, DebugRenderer renderer,
RMat44Arg transform) {
long poseVa = va();
long settingsVa = settings.va();
long rendererVa = renderer.va();
long transformVa = transform.targetVa();
draw(poseVa, settingsVa, rendererVa, transformVa);
}

/**
* Access the transforms of the specified joint.
*
Expand Down Expand Up @@ -103,10 +142,15 @@ public void setSkeleton(Skeleton skeleton) {

native private static void calculateJointMatrices(long poseVa);

native private static void calculateJointStates(long poseVa);

native private static long createCopy(long poseVa);

native private static long createSkeletonPoseDefault();

native private static void draw(
long poseVa, long settingsVa, long rendererVa, long transformVa);

native private static void free(long poseVa);

native private static long getJoint(long poseVa, int jointIndex);
Expand Down
33 changes: 32 additions & 1 deletion src/main/native/glue/s/SkeletonPose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_SkeletonPose_calculat
pPose->CalculateJointMatrices();
}

/*
* Class: com_github_stephengold_joltjni_SkeletonPose
* Method: calculateJointStates
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_SkeletonPose_calculateJointStates
(JNIEnv *, jclass, jlong poseVa) {
SkeletonPose * const pPose = reinterpret_cast<SkeletonPose *> (poseVa);
pPose->CalculateJointStates();
}

/*
* Class: com_github_stephengold_joltjni_SkeletonPose
* Method: createCopy
Expand All @@ -67,6 +78,26 @@ JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_SkeletonPose_createS
return reinterpret_cast<jlong> (pResult);
}

/*
* Class: com_github_stephengold_joltjni_SkeletonPose
* Method: draw
* Signature: (JJJJ)V
*/
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_SkeletonPose_draw
(JNIEnv *, jclass, jlong poseVa, jlong settingsVa, jlong rendererVa,
jlong transformVa) {
#ifdef JPH_DEBUG_RENDERER
const SkeletonPose * const pPose = reinterpret_cast<SkeletonPose *> (poseVa);
const SkeletonPose::DrawSettings * const pSettings
= reinterpret_cast<SkeletonPose::DrawSettings *> (settingsVa);
DebugRenderer * const pRenderer
= reinterpret_cast<DebugRenderer *> (rendererVa);
const RMat44 * const pTransform
= reinterpret_cast<RMat44 *> (transformVa);
pPose->Draw(*pSettings, pRenderer, *pTransform);
#endif
}

/*
* Class: com_github_stephengold_joltjni_SkeletonPose
* Method: free
Expand Down Expand Up @@ -114,4 +145,4 @@ JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_SkeletonPose_setSkele
const Skeleton * const pSkeleton
= reinterpret_cast<Skeleton *> (skeletonVa);
pPose->SetSkeleton(pSkeleton);
}
}

0 comments on commit f92c831

Please sign in to comment.