Skip to content

Commit

Permalink
add the SoftBodyContactSettings class
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Feb 8, 2025
1 parent abf0c7a commit 0be2fbb
Show file tree
Hide file tree
Showing 3 changed files with 344 additions and 0 deletions.
1 change: 1 addition & 0 deletions Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ $(N)/glue/s/SkeletonPoseDrawSettings.cpp \
$(N)/glue/s/SliderConstraint.cpp \
$(N)/glue/s/SliderConstraintSettings.cpp \
$(N)/glue/s/SoftBodyContactListener.cpp \
$(N)/glue/s/SoftBodyContactSettings.cpp \
$(N)/glue/s/SoftBodyCreationSettings.cpp \
$(N)/glue/s/SoftBodyManifold.cpp \
$(N)/glue/s/SoftBodyMotionProperties.cpp \
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
/*
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.
*/
package com.github.stephengold.joltjni;

import com.github.stephengold.joltjni.readonly.ConstSoftBodyContactSettings;

/**
* Properties of a contact constraint that can be overridden during certain
* {@code SoftBodyContactListener} callbacks.
*
* @author Stephen Gold [email protected]
*/
public class SoftBodyContactSettings
extends JoltPhysicsObject
implements ConstSoftBodyContactSettings {
// *************************************************************************
// constructors

/**
* Instantiate the default settings for testing.
*/
public SoftBodyContactSettings() {
long settingsVa = createDefault();
setVirtualAddress(settingsVa, () -> free(settingsVa));
}

/**
* Instantiate settings with the specified native object assigned but not
* owned.
*
* @param settingsVa the virtual address of the native object to assign (not
* zero)
*/
public SoftBodyContactSettings(long settingsVa) {
setVirtualAddress(settingsVa);
}
// *************************************************************************
// new methods exposed

/**
* Alter the scale factor for the inverse inertia of body 2. (native
* attribute: mInvInertiaScale2)
*
* @param factor the factor (0 = infinite inertia, 1 = use original inertia,
* default=1)
*/
public void setInvInertiaScale2(float factor) {
long settingsVa = va();
setInvInertiaScale2(settingsVa, factor);
}

/**
* Alter the scale factor for the inverse mass of the soft body. (native
* attribute: mInvMassScale1)
*
* @param factor the factor (0 = infinite mass, 1 = use original mass,
* default=1)
*/
public void setInvMassScale1(float factor) {
long settingsVa = va();
setInvMassScale1(settingsVa, factor);
}

/**
* Alter the scale factor for the inverse mass of body 2. (native attribute:
* mInvMassScale2)
*
* @param factor the factor (0 = infinite mass, 1 = use original mass,
* default=1)
*/
public void setInvMassScale2(float factor) {
long settingsVa = va();
setInvMassScale2(settingsVa, factor);
}

/**
* Alter whether the contact should be treated as a sensor (no collision
* response). (native attribute: mIsSensor)
*
* @param setting {@code true} to treat as a sensor, otherwise {@code false}
* (default=false)
*/
public void setIsSensor(boolean setting) {
long settingsVa = va();
setIsSensor(settingsVa, setting);
}
// *************************************************************************
// ConstSoftBodyContactSettings methods

/**
* Return the scale factor for the inverse inertia of body 2. The settings
* are unaffected. (native attribute: mInvInertiaScale2)
*
* @return the factor (0 = infinite inertia, 1 = use original inertia)
*/
@Override
public float getInvInertiaScale2() {
long settingsVa = va();
float result = getInvInertiaScale2(settingsVa);

return result;
}

/**
* Return the scale factor for the inverse mass of the soft body. The
* settings are unaffected. (native attribute: mInvMassScale1)
*
* @return the factor (0 = infinite mass, 1 = use original mass)
*/
@Override
public float getInvMassScale1() {
long settingsVa = va();
float result = getInvMassScale1(settingsVa);

return result;
}

/**
* Return the scale factor for the inverse mass of body 2. The settings are
* unaffected. (native attribute: mInvMassScale2)
*
* @return the factor (0 = infinite mass, 1 = use original mass)
*/
@Override
public float getInvMassScale2() {
long settingsVa = va();
float result = getInvMassScale2(settingsVa);

return result;
}

/**
* Test whether the contact should be treated as a sensor (no collision
* response). The settings are unaffected. (native attribute: mIsSensor)
*
* @return {@code true} if treated as a sensor, otherwise {@code false}
*/
@Override
public boolean getIsSensor() {
long settingsVa = va();
boolean result = getIsSensor(settingsVa);

return result;
}
// *************************************************************************
// native private methods

native private static long createDefault();

native private static void free(long settingsVa);

native private static float getInvInertiaScale2(long settingsVa);

native private static float getInvMassScale1(long settingsVa);

native private static float getInvMassScale2(long settingsVa);

native private static boolean getIsSensor(long settingsVa);

native private static void setInvInertiaScale2(
long settingsVa, float scale);

native private static void setInvMassScale1(long settingsVa, float scale);

native private static void setInvMassScale2(long settingsVa, float scale);

native private static void setIsSensor(long settingsVa, boolean setting);
}
156 changes: 156 additions & 0 deletions src/main/native/glue/s/SoftBodyContactSettings.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
/*
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/SoftBodyContactListener.h"
#include "auto/com_github_stephengold_joltjni_SoftBodyContactSettings.h"
#include "glue/glue.h"

using namespace JPH;

/*
* Class: com_github_stephengold_joltjni_SoftBodyContactSettings
* Method: createDefault
* Signature: ()J
*/
JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_SoftBodyContactSettings_createDefault
(JNIEnv *, jclass) {
SoftBodyContactSettings * const pSettings = new SoftBodyContactSettings();
TRACE_NEW("SoftBodyContactSettings", pSettings)
return reinterpret_cast<jlong> (pSettings);
}

/*
* Class: com_github_stephengold_joltjni_SoftBodyContactSettings
* Method: free
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_SoftBodyContactSettings_free
(JNIEnv *, jclass, jlong settingsVa) {
SoftBodyContactSettings * const pSettings
= reinterpret_cast<SoftBodyContactSettings *> (settingsVa);
TRACE_DELETE("ContactSettings", pSettings)
delete pSettings;
}

/*
* Class: com_github_stephengold_joltjni_SoftBodyContactSettings
* Method: getInvInertiaScale2
* Signature: (J)F
*/
JNIEXPORT jfloat JNICALL Java_com_github_stephengold_joltjni_SoftBodyContactSettings_getInvInertiaScale2
(JNIEnv *, jclass, jlong settingsVa) {
const SoftBodyContactSettings * const pSettings
= reinterpret_cast<SoftBodyContactSettings *> (settingsVa);
const float result = pSettings->mInvInertiaScale2;
return result;
}

/*
* Class: com_github_stephengold_joltjni_SoftBodyContactSettings
* Method: getInvMassScale1
* Signature: (J)F
*/
JNIEXPORT jfloat JNICALL Java_com_github_stephengold_joltjni_SoftBodyContactSettings_getInvMassScale1
(JNIEnv *, jclass, jlong settingsVa) {
const SoftBodyContactSettings * const pSettings
= reinterpret_cast<SoftBodyContactSettings *> (settingsVa);
const float result = pSettings->mInvMassScale1;
return result;
}

/*
* Class: com_github_stephengold_joltjni_SoftBodyContactSettings
* Method: getInvMassScale2
* Signature: (J)F
*/
JNIEXPORT jfloat JNICALL Java_com_github_stephengold_joltjni_SoftBodyContactSettings_getInvMassScale2
(JNIEnv *, jclass, jlong settingsVa) {
const SoftBodyContactSettings * const pSettings
= reinterpret_cast<SoftBodyContactSettings *> (settingsVa);
const float result = pSettings->mInvMassScale2;
return result;
}

/*
* Class: com_github_stephengold_joltjni_SoftBodyContactSettings
* Method: getIsSensor
* Signature: (J)Z
*/
JNIEXPORT jboolean JNICALL Java_com_github_stephengold_joltjni_SoftBodyContactSettings_getIsSensor
(JNIEnv *, jclass, jlong settingsVa) {
const SoftBodyContactSettings * const pSettings
= reinterpret_cast<SoftBodyContactSettings *> (settingsVa);
const bool result = pSettings->mIsSensor;
return result;
}

/*
* Class: com_github_stephengold_joltjni_SoftBodyContactSettings
* Method: setInvInertiaScale2
* Signature: (JF)V
*/
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_SoftBodyContactSettings_setInvInertiaScale2
(JNIEnv *, jclass, jlong settingsVa, jfloat scale) {
SoftBodyContactSettings * const pSettings
= reinterpret_cast<SoftBodyContactSettings *> (settingsVa);
pSettings->mInvInertiaScale2 = scale;
}

/*
* Class: com_github_stephengold_joltjni_SoftBodyContactSettings
* Method: setInvMassScale1
* Signature: (JF)V
*/
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_SoftBodyContactSettings_setInvMassScale1
(JNIEnv *, jclass, jlong settingsVa, jfloat scale) {
SoftBodyContactSettings * const pSettings
= reinterpret_cast<SoftBodyContactSettings *> (settingsVa);
pSettings->mInvMassScale1 = scale;
}

/*
* Class: com_github_stephengold_joltjni_SoftBodyContactSettings
* Method: setInvMassScale2
* Signature: (JF)V
*/
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_SoftBodyContactSettings_setInvMassScale2
(JNIEnv *, jclass, jlong settingsVa, jfloat scale) {
SoftBodyContactSettings * const pSettings
= reinterpret_cast<SoftBodyContactSettings *> (settingsVa);
pSettings->mInvMassScale2 = scale;
}

/*
* Class: com_github_stephengold_joltjni_SoftBodyContactSettings
* Method: setIsSensor
* Signature: (JZ)V
*/
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_SoftBodyContactSettings_setIsSensor
(JNIEnv *, jclass, jlong settingsVa, jboolean setting) {
SoftBodyContactSettings * const pSettings
= reinterpret_cast<SoftBodyContactSettings *> (settingsVa);
pSettings->mIsSensor = setting;
}

0 comments on commit 0be2fbb

Please sign in to comment.