Skip to content

Commit

Permalink
BodyInterface: add the activateBody() and setAngularVelocity() methods
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Jun 28, 2024
1 parent 88402b4 commit 6deb4d1
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/main/java/com/github/stephengold/joltjni/BodyInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ public class BodyInterface extends NonCopyable {
// *************************************************************************
// new methods exposed

/**
* Activate the specified body.
*
* @param bodyId which body to activate (not null)
*/
public void activateBody(BodyId bodyId) {
long bodyInterfaceVa = va();
long bodyIdVa = bodyId.va();
activateBody(bodyInterfaceVa, bodyIdVa);
}

/**
* Add the specified body to the physics system.
*
Expand Down Expand Up @@ -152,6 +163,19 @@ public boolean isActive(BodyId bodyId) {
return result;
}

/**
* Alter the linear velocity of the specified body.
*
* @param bodyId the ID of the body to test (not null)
* @param omega the desired rates (not null, unaffected)
*/
public void setAngularVelocity(BodyId bodyId, Vec3 omega) {
long bodyInterfaceVa = va();
long bodyIdVa = bodyId.va();
setAngularVelocity(bodyInterfaceVa, bodyIdVa,
omega.getX(), omega.getY(), omega.getZ());
}

/**
* Alter the linear velocity of the specified body.
*
Expand All @@ -166,6 +190,9 @@ public void setLinearVelocity(BodyId bodyId, Vec3 velocity) {
// *************************************************************************
// native private methods

native private static void activateBody(
long bodyInterfaceVa, long bodyIdVa);

native private static void addBody(
long bodyInterfaceVa, long bodyIdVa, int activationOrdinal);

Expand Down Expand Up @@ -201,6 +228,9 @@ native private static float getLinearVelocityZ(
native private static void removeBody(
long bodyInterfaceVa, long bodyIdVa);

native private static void setAngularVelocity(
long bodyInterfaceVa, long bodyIdVa, float wx, float wy, float wz);

native private static void setLinearVelocity(
long bodyInterfaceVa, long bodyIdVa, float vx, float vy, float vz);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ SOFTWARE.

using namespace JPH;

/*
* Class: com_github_stephengold_joltjni_BodyInterface
* Method: activateBody
* Signature: (JJ)V
*/
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_BodyInterface_activateBody
(JNIEnv *, jclass, jlong bodyInterfaceVa, jlong bodyIdVa) {
BodyInterface * const pInterface
= reinterpret_cast<BodyInterface *> (bodyInterfaceVa);
const BodyID * const pBodyId = reinterpret_cast<BodyID *> (bodyIdVa);
pInterface->ActivateBody(*pBodyId);
}

/*
* Class: com_github_stephengold_joltjni_BodyInterface
* Method: addBody
Expand Down Expand Up @@ -199,6 +212,21 @@ JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_BodyInterface_removeB
pInterface->RemoveBody(*pBodyId);
}

/*
* Class: com_github_stephengold_joltjni_BodyInterface
* Method: setAngularVelocity
* Signature: (JJFFF)V
*/
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_BodyInterface_setAngularVelocity
(JNIEnv *, jclass, jlong bodyInterfaceVa, jlong bodyIdVa,
jfloat wx, jfloat wy, jfloat wz) {
BodyInterface * const pInterface
= reinterpret_cast<BodyInterface *> (bodyInterfaceVa);
const BodyID * const pBodyId = reinterpret_cast<BodyID *> (bodyIdVa);
const Vec3 omega(wx, wy, wz);
pInterface->SetAngularVelocity(*pBodyId, omega);
}

/*
* Class: com_github_stephengold_joltjni_BodyInterface
* Method: setLinearVelocity
Expand Down

0 comments on commit 6deb4d1

Please sign in to comment.