From 30d1ecaec2ea995ddcc39cdcfca015c903a369e1 Mon Sep 17 00:00:00 2001 From: Stephen Gold Date: Tue, 17 Sep 2019 13:27:08 -0700 Subject: [PATCH] fix for issue #1157 (can't enable a TranslationalLimitMotor) --- ..._joints_motors_TranslationalLimitMotor.cpp | 39 ++++++++++++++++++- .../com/jme3/bullet/joints/SixDofJoint.java | 10 +++++ .../motors/TranslationalLimitMotor.java | 28 ++++++++++++- 3 files changed, 75 insertions(+), 2 deletions(-) diff --git a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_joints_motors_TranslationalLimitMotor.cpp b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_joints_motors_TranslationalLimitMotor.cpp index 39db519e7..14e66933f 100644 --- a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_joints_motors_TranslationalLimitMotor.cpp +++ b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_joints_motors_TranslationalLimitMotor.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2012 jMonkeyEngine + * Copyright (c) 2009-2019 jMonkeyEngine * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -232,6 +232,43 @@ extern "C" { motor->m_restitution = value; } + /* + * Class: com_jme3_bullet_joints_motors_TranslationalLimitMotor + * Method: setEnabled + * Signature: (JIZ)V + */ + JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_motors_TranslationalLimitMotor_setEnabled + (JNIEnv *env, jobject object, jlong motorId, jint axisIndex, jboolean newSetting) { + btTranslationalLimitMotor *pMotor + = reinterpret_cast (motorId); + if (pMotor == NULL) { + jclass newExc = env->FindClass("java/lang/NullPointerException"); + env->ThrowNew(newExc, "The native object does not exist."); + return; + } + + pMotor->m_enableMotor[axisIndex] = (bool)newSetting; + } + + /* + * Class: com_jme3_bullet_joints_motors_TranslationalLimitMotor + * Method: isEnabled + * Signature: (JI)Z + */ + JNIEXPORT jboolean JNICALL Java_com_jme3_bullet_joints_motors_TranslationalLimitMotor_isEnabled + (JNIEnv *env, jobject object, jlong motorId, jint axisIndex) { + btTranslationalLimitMotor *pMotor + = reinterpret_cast (motorId); + if (pMotor == NULL) { + jclass newExc = env->FindClass("java/lang/NullPointerException"); + env->ThrowNew(newExc, "The native object does not exist."); + return 0; + } + + bool result = pMotor->m_enableMotor[axisIndex]; + return (jboolean) result; + } + #ifdef __cplusplus } #endif diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/joints/SixDofJoint.java b/jme3-bullet/src/main/java/com/jme3/bullet/joints/SixDofJoint.java index 660319a18..74ab70cbc 100644 --- a/jme3-bullet/src/main/java/com/jme3/bullet/joints/SixDofJoint.java +++ b/jme3-bullet/src/main/java/com/jme3/bullet/joints/SixDofJoint.java @@ -281,6 +281,11 @@ public class SixDofJoint extends PhysicsJoint { getTranslationalLimitMotor().setLowerLimit((Vector3f) capsule.readSavable("transMotor_LowerLimit", Vector3f.ZERO)); getTranslationalLimitMotor().setRestitution(capsule.readFloat("transMotor_Restitution", 0.5f)); getTranslationalLimitMotor().setUpperLimit((Vector3f) capsule.readSavable("transMotor_UpperLimit", Vector3f.ZERO)); + + for (int axisIndex = 0; axisIndex < 3; ++axisIndex) { + translationalMotor.setEnabled(axisIndex, capsule.readBoolean( + "transMotor_Enable" + axisIndex, false)); + } } /** @@ -318,5 +323,10 @@ public class SixDofJoint extends PhysicsJoint { capsule.write(getTranslationalLimitMotor().getLowerLimit(), "transMotor_LowerLimit", Vector3f.ZERO); capsule.write(getTranslationalLimitMotor().getRestitution(), "transMotor_Restitution", 0.5f); capsule.write(getTranslationalLimitMotor().getUpperLimit(), "transMotor_UpperLimit", Vector3f.ZERO); + + for (int axisIndex = 0; axisIndex < 3; ++axisIndex) { + capsule.write(translationalMotor.isEnabled(axisIndex), + "transMotor_Enable" + axisIndex, false); + } } } diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/joints/motors/TranslationalLimitMotor.java b/jme3-bullet/src/main/java/com/jme3/bullet/joints/motors/TranslationalLimitMotor.java index 97993edd3..4fbf0cb89 100644 --- a/jme3-bullet/src/main/java/com/jme3/bullet/joints/motors/TranslationalLimitMotor.java +++ b/jme3-bullet/src/main/java/com/jme3/bullet/joints/motors/TranslationalLimitMotor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2018 jMonkeyEngine + * Copyright (c) 2009-2019 jMonkeyEngine * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -204,4 +204,30 @@ public class TranslationalLimitMotor { } private native void setRestitution(long motorId, float restitution); + + /** + * Enable or disable the indexed axis. + * + * @param axisIndex which axis: 0→X, 1→Y, 2→Z + * @param enableMotor true→enable, false→disable (default=false) + */ + public void setEnabled(int axisIndex, boolean enableMotor) { + setEnabled(motorId, axisIndex, enableMotor); + } + + native private void setEnabled(long motorId, int axisIndex, + boolean enableMotor); + + /** + * Test whether the indexed axis is enabled. + * + * @param axisIndex which axis: 0→X, 1→Y, 2→Z + * @return true if enabled, otherwise false + */ + public boolean isEnabled(int axisIndex) { + boolean result = isEnabled(motorId, axisIndex); + return result; + } + + native private boolean isEnabled(long motorId, int axisIndex); }