Skip to content

Commit 30d1eca

Browse files
committed
fix for issue #1157 (can't enable a TranslationalLimitMotor)
1 parent 3c74fe5 commit 30d1eca

3 files changed

Lines changed: 75 additions & 2 deletions

File tree

jme3-bullet-native/src/native/cpp/com_jme3_bullet_joints_motors_TranslationalLimitMotor.cpp

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009-2012 jMonkeyEngine
2+
* Copyright (c) 2009-2019 jMonkeyEngine
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -232,6 +232,43 @@ extern "C" {
232232
motor->m_restitution = value;
233233
}
234234

235+
/*
236+
* Class: com_jme3_bullet_joints_motors_TranslationalLimitMotor
237+
* Method: setEnabled
238+
* Signature: (JIZ)V
239+
*/
240+
JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_motors_TranslationalLimitMotor_setEnabled
241+
(JNIEnv *env, jobject object, jlong motorId, jint axisIndex, jboolean newSetting) {
242+
btTranslationalLimitMotor *pMotor
243+
= reinterpret_cast<btTranslationalLimitMotor *> (motorId);
244+
if (pMotor == NULL) {
245+
jclass newExc = env->FindClass("java/lang/NullPointerException");
246+
env->ThrowNew(newExc, "The native object does not exist.");
247+
return;
248+
}
249+
250+
pMotor->m_enableMotor[axisIndex] = (bool)newSetting;
251+
}
252+
253+
/*
254+
* Class: com_jme3_bullet_joints_motors_TranslationalLimitMotor
255+
* Method: isEnabled
256+
* Signature: (JI)Z
257+
*/
258+
JNIEXPORT jboolean JNICALL Java_com_jme3_bullet_joints_motors_TranslationalLimitMotor_isEnabled
259+
(JNIEnv *env, jobject object, jlong motorId, jint axisIndex) {
260+
btTranslationalLimitMotor *pMotor
261+
= reinterpret_cast<btTranslationalLimitMotor *> (motorId);
262+
if (pMotor == NULL) {
263+
jclass newExc = env->FindClass("java/lang/NullPointerException");
264+
env->ThrowNew(newExc, "The native object does not exist.");
265+
return 0;
266+
}
267+
268+
bool result = pMotor->m_enableMotor[axisIndex];
269+
return (jboolean) result;
270+
}
271+
235272
#ifdef __cplusplus
236273
}
237274
#endif

jme3-bullet/src/main/java/com/jme3/bullet/joints/SixDofJoint.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,11 @@ public void read(JmeImporter im) throws IOException {
281281
getTranslationalLimitMotor().setLowerLimit((Vector3f) capsule.readSavable("transMotor_LowerLimit", Vector3f.ZERO));
282282
getTranslationalLimitMotor().setRestitution(capsule.readFloat("transMotor_Restitution", 0.5f));
283283
getTranslationalLimitMotor().setUpperLimit((Vector3f) capsule.readSavable("transMotor_UpperLimit", Vector3f.ZERO));
284+
285+
for (int axisIndex = 0; axisIndex < 3; ++axisIndex) {
286+
translationalMotor.setEnabled(axisIndex, capsule.readBoolean(
287+
"transMotor_Enable" + axisIndex, false));
288+
}
284289
}
285290

286291
/**
@@ -318,5 +323,10 @@ public void write(JmeExporter ex) throws IOException {
318323
capsule.write(getTranslationalLimitMotor().getLowerLimit(), "transMotor_LowerLimit", Vector3f.ZERO);
319324
capsule.write(getTranslationalLimitMotor().getRestitution(), "transMotor_Restitution", 0.5f);
320325
capsule.write(getTranslationalLimitMotor().getUpperLimit(), "transMotor_UpperLimit", Vector3f.ZERO);
326+
327+
for (int axisIndex = 0; axisIndex < 3; ++axisIndex) {
328+
capsule.write(translationalMotor.isEnabled(axisIndex),
329+
"transMotor_Enable" + axisIndex, false);
330+
}
321331
}
322332
}

jme3-bullet/src/main/java/com/jme3/bullet/joints/motors/TranslationalLimitMotor.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009-2018 jMonkeyEngine
2+
* Copyright (c) 2009-2019 jMonkeyEngine
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -204,4 +204,30 @@ public void setRestitution(float restitution) {
204204
}
205205

206206
private native void setRestitution(long motorId, float restitution);
207+
208+
/**
209+
* Enable or disable the indexed axis.
210+
*
211+
* @param axisIndex which axis: 0&rarr;X, 1&rarr;Y, 2&rarr;Z
212+
* @param enableMotor true&rarr;enable, false&rarr;disable (default=false)
213+
*/
214+
public void setEnabled(int axisIndex, boolean enableMotor) {
215+
setEnabled(motorId, axisIndex, enableMotor);
216+
}
217+
218+
native private void setEnabled(long motorId, int axisIndex,
219+
boolean enableMotor);
220+
221+
/**
222+
* Test whether the indexed axis is enabled.
223+
*
224+
* @param axisIndex which axis: 0&rarr;X, 1&rarr;Y, 2&rarr;Z
225+
* @return true if enabled, otherwise false
226+
*/
227+
public boolean isEnabled(int axisIndex) {
228+
boolean result = isEnabled(motorId, axisIndex);
229+
return result;
230+
}
231+
232+
native private boolean isEnabled(long motorId, int axisIndex);
207233
}

0 commit comments

Comments
 (0)