Skip to content

Commit

Permalink
add the SoftBodyMotionProperties class
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Feb 7, 2025
1 parent 1af8e0e commit 611296a
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 5 deletions.
1 change: 1 addition & 0 deletions Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ $(N)/glue/s/SkeletonPoseDrawSettings.cpp \
$(N)/glue/s/SliderConstraint.cpp \
$(N)/glue/s/SliderConstraintSettings.cpp \
$(N)/glue/s/SoftBodyCreationSettings.cpp \
$(N)/glue/s/SoftBodyMotionProperties.cpp \
$(N)/glue/s/SoftBodySharedSettings.cpp \
$(N)/glue/s/SpecifiedBroadPhaseLayerFilter.cpp \
$(N)/glue/s/SpecifiedObjectLayerFilter.cpp \
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/com/github/stephengold/joltjni/Body.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,11 @@ public MotionProperties getMotionProperties() {
result = null;
} else {
long propertiesVa = getMotionProperties(bodyVa);
result = new MotionProperties(propertiesVa);
if (isSoftBody(bodyVa)) {
result = new SoftBodyMotionProperties(this, propertiesVa);
} else {
result = new MotionProperties(this, propertiesVa);
}
}

return result;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2024 Stephen Gold
Copyright (c) 2024-2025 Stephen Gold
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -45,13 +45,14 @@ public MotionProperties() {
}

/**
* Instantiate with the specified native object assigned.
* Instantiate with the specified container and native object.
*
* @param container the containing object, or {@code null} if none
* @param propertiesVa the virtual address of the native object to assign
* (not zero)
*/
MotionProperties(long propertiesVa) {
super(propertiesVa);
MotionProperties(JoltPhysicsObject container, long propertiesVa) {
super(container, propertiesVa);
}
// *************************************************************************
// new methods exposed
Expand Down
136 changes: 136 additions & 0 deletions src/main/native/glue/s/SoftBodyMotionProperties.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/*
Copyright (c) 2025 Stephen Gold
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

/*
* Author: Stephen Gold
*/
#include "Jolt/Jolt.h"
#include "Jolt/Physics/SoftBody/SoftBodyMotionProperties.h"
#include "auto/com_github_stephengold_joltjni_SoftBodyMotionProperties.h"

using namespace JPH;

/*
* Class: com_github_stephengold_joltjni_SoftBodyMotionProperties
* Method: countFaces
* Signature: (J)I
*/
JNIEXPORT jint JNICALL Java_com_github_stephengold_joltjni_SoftBodyMotionProperties_countFaces
(JNIEnv *, jclass, jlong propertiesVa) {
const SoftBodyMotionProperties * const pProperties
= reinterpret_cast<SoftBodyMotionProperties *> (propertiesVa);
const Array<SoftBodySharedSettings::Face>& faces = pProperties->GetFaces();
const Array<SoftBodySharedSettings::Face>::size_type result = faces.size();
return result;
}

/*
* Class: com_github_stephengold_joltjni_SoftBodyMotionProperties
* Method: countVertices
* Signature: (J)I
*/
JNIEXPORT jint JNICALL Java_com_github_stephengold_joltjni_SoftBodyMotionProperties_countVertices
(JNIEnv *, jclass, jlong propertiesVa) {
const SoftBodyMotionProperties * const pProperties
= reinterpret_cast<SoftBodyMotionProperties *> (propertiesVa);
const Array<SoftBodyVertex>& vertices = pProperties->GetVertices();
const Array<SoftBodyVertex>::size_type result = vertices.size();
return result;
}

/*
* Class: com_github_stephengold_joltjni_SoftBodyMotionProperties
* Method: customUpdate
* Signature: (JFJJ)V
*/
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_SoftBodyMotionProperties_customUpdate
(JNIEnv *, jclass, jlong propertiesVa, jfloat deltaTime, jlong bodyVa, jlong systemVa) {
SoftBodyMotionProperties * const pProperties
= reinterpret_cast<SoftBodyMotionProperties *> (propertiesVa);
Body * const pBody = reinterpret_cast<Body *> (bodyVa);
PhysicsSystem * const pSystem = reinterpret_cast<PhysicsSystem *> (systemVa);
pProperties->CustomUpdate(deltaTime, *pBody, *pSystem);
}

/*
* Class: com_github_stephengold_joltjni_SoftBodyMotionProperties
* Method: getFace
* Signature: (JI)J
*/
JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_SoftBodyMotionProperties_getFace
(JNIEnv *, jclass, jlong propertiesVa, jint index) {
SoftBodyMotionProperties * const pProperties
= reinterpret_cast<SoftBodyMotionProperties *> (propertiesVa);
const SoftBodySharedSettings::Face& result = pProperties->GetFace(index);
return reinterpret_cast<jlong> (&result);
}

/*
* Class: com_github_stephengold_joltjni_SoftBodyMotionProperties
* Method: getNumIterations
* Signature: (J)I
*/
JNIEXPORT jint JNICALL Java_com_github_stephengold_joltjni_SoftBodyMotionProperties_getNumIterations
(JNIEnv *, jclass, jlong propertiesVa) {
const SoftBodyMotionProperties * const pProperties
= reinterpret_cast<SoftBodyMotionProperties *> (propertiesVa);
const uint32 result = pProperties->GetNumIterations();
return result;
}

/*
* Class: com_github_stephengold_joltjni_SoftBodyMotionProperties
* Method: getSettings
* Signature: (J)J
*/
JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_SoftBodyMotionProperties_getSettings
(JNIEnv *, jclass, jlong propertiesVa) {
SoftBodyMotionProperties * const pProperties
= reinterpret_cast<SoftBodyMotionProperties *> (propertiesVa);
const SoftBodySharedSettings * const pResult = pProperties->GetSettings();
return reinterpret_cast<jlong> (pResult);
}

/*
* Class: com_github_stephengold_joltjni_SoftBodyMotionProperties
* Method: getVertex
* Signature: (JI)J
*/
JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_SoftBodyMotionProperties_getVertex
(JNIEnv *, jclass, jlong propertiesVa, jint index) {
SoftBodyMotionProperties * const pProperties
= reinterpret_cast<SoftBodyMotionProperties *> (propertiesVa);
const SoftBodyVertex& result = pProperties->GetVertex(index);
return reinterpret_cast<jlong> (&result);
}

/*
* Class: com_github_stephengold_joltjni_SoftBodyMotionProperties
* Method: setNumIterations
* Signature: (JI)V
*/
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_SoftBodyMotionProperties_setNumIterations
(JNIEnv *, jclass, jlong propertiesVa, jint numIterations) {
SoftBodyMotionProperties * const pProperties
= reinterpret_cast<SoftBodyMotionProperties *> (propertiesVa);
pProperties->SetNumIterations(numIterations);
}

0 comments on commit 611296a

Please sign in to comment.