Skip to content

Commit

Permalink
BodyInterface: add the createSoftBody() method
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Oct 10, 2024
1 parent 90b1dd1 commit 1a79d22
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/main/java/com/github/stephengold/joltjni/BodyInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ of this software and associated documentation files (the "Software"), to deal
import com.github.stephengold.joltjni.enumerate.EMotionType;
import com.github.stephengold.joltjni.readonly.ConstBodyCreationSettings;
import com.github.stephengold.joltjni.readonly.ConstBodyId;
import com.github.stephengold.joltjni.readonly.ConstSoftBodyCreationSettings;
import com.github.stephengold.joltjni.readonly.QuatArg;
import com.github.stephengold.joltjni.readonly.RVec3Arg;
import com.github.stephengold.joltjni.readonly.Vec3Arg;
Expand Down Expand Up @@ -188,6 +189,22 @@ public BodyId createAndAddBody(
return result;
}

/**
* Create a soft body and add it to the physics system.
*
* @param settings the settings to use (not null, unaffected)
* @param activationMode whether to activate the body (not null)
* @return the ID of the created body, or an invalid ID when out of bodies
*/
public BodyId createAndAddSoftBody(ConstSoftBodyCreationSettings settings,
EActivation activationMode) {
Body body = createSoftBody(settings);
BodyId result = body.getId();
addBody(result, activationMode);

return result;
}

/**
* Create a rigid body using the specified settings.
*
Expand Down Expand Up @@ -229,6 +246,24 @@ public TwoBodyConstraint createConstraint(
return result;
}

/**
* Create a soft body using the specified settings.
*
* @param settings the settings to use (not null, unaffected)
* @return the new body
*/
public Body createSoftBody(ConstSoftBodyCreationSettings settings) {
long bodyInterfaceVa = va();
long settingsVa = settings.va();
long bodyVa = createSoftBody(bodyInterfaceVa, settingsVa);
if (bodyVa == 0L) {
throw new IllegalStateException("ran out of bodies");
}
Body result = new Body(bodyVa);

return result;
}

/**
* Deactivate the specified body.
*
Expand Down Expand Up @@ -679,6 +714,9 @@ native private static long createBody(
native private static long createConstraint(long bodyInterfaceVa,
long settingsVa, long body1IdVa, long body2IdVa);

native private static long createSoftBody(
long bodyInterfaceVa, long settingsVa);

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

Expand Down
15 changes: 15 additions & 0 deletions src/main/native/glue/bo/BodyInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,21 @@ JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_BodyInterface_create
return reinterpret_cast<jlong> (pResult);
}

/*
* Class: com_github_stephengold_joltjni_BodyInterface
* Method: createSoftBody
* Signature: (JJ)J
*/
JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_BodyInterface_createSoftBody
(JNIEnv *, jclass, jlong bodyInterfaceVa, jlong settingsVa) {
BodyInterface * const pInterface
= reinterpret_cast<BodyInterface *> (bodyInterfaceVa);
const SoftBodyCreationSettings * const pSettings
= reinterpret_cast<SoftBodyCreationSettings *> (settingsVa);
const Body * const pResult = pInterface->CreateSoftBody(*pSettings);
return reinterpret_cast<jlong> (pResult);
}

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

0 comments on commit 1a79d22

Please sign in to comment.