Skip to content

Commit cd1d145

Browse files
committed
PhysicsSpace: add method to set solver iterations
Thanks to Seppes (see thread: http://hub.jmonkeyengine.org/t/how-to-access-native-bullets-constraintsolver-numiterations)
1 parent f7d544f commit cd1d145

4 files changed

Lines changed: 60 additions & 1 deletion

File tree

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,18 @@ extern "C" {
528528
space->getDynamicsWorld()->convexSweepTest((btConvexShape *) shape, native_from, native_to, resultCallback, native_allowed_ccd_penetration);
529529
return;
530530
}
531+
532+
JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_setSolverNumIterations
533+
(JNIEnv *env, jobject object, jlong spaceId, jint value) {
534+
jmePhysicsSpace* space = reinterpret_cast<jmePhysicsSpace*>(spaceId);
535+
if (space == NULL) {
536+
jclass newExc = env->FindClass("java/lang/NullPointerException");
537+
env->ThrowNew(newExc, "The physics space does not exist.");
538+
return;
539+
}
540+
541+
space->getDynamicsWorld()->getSolverInfo().m_numIterations = value;
542+
}
531543

532544
#ifdef __cplusplus
533545
}

jme3-bullet-native/src/native/cpp/com_jme3_bullet_PhysicsSpace.h

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jme3-bullet/src/main/java/com/jme3/bullet/PhysicsSpace.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ protected ConcurrentLinkedQueue<AppTask<?>> initialValue() {
102102
private Vector3f worldMax = new Vector3f(10000f, 10000f, 10000f);
103103
private float accuracy = 1f / 60f;
104104
private int maxSubSteps = 4, rayTestFlags = 1 << 2;
105+
private int solverNumIterations = 10;
105106

106107
static {
107108
// System.loadLibrary("bulletjme");
@@ -871,7 +872,7 @@ public float addSingleResult(LocalConvexResult lcr, boolean bln) {
871872
}
872873
873874
*/
874-
875+
875876
/**
876877
* destroys the current PhysicsSpace so that a new one can be created
877878
*/
@@ -958,6 +959,29 @@ public void setWorldMax(Vector3f worldMax) {
958959
this.worldMax.set(worldMax);
959960
}
960961

962+
/**
963+
* Set the number of iterations used by the contact solver.
964+
*
965+
* The default is 10. Use 4 for low quality, 20 for high quality.
966+
*
967+
* @param numIterations The number of iterations used by the contact & constraint solver.
968+
*/
969+
public void setSolverNumIterations(int numIterations) {
970+
this.solverNumIterations = numIterations;
971+
setSolverNumIterations(physicsSpaceId, numIterations);
972+
}
973+
974+
/**
975+
* Get the number of iterations used by the contact solver.
976+
*
977+
* @return The number of iterations used by the contact & constraint solver.
978+
*/
979+
public int getSolverNumIterations() {
980+
return solverNumIterations;
981+
}
982+
983+
private static native void setSolverNumIterations(long physicsSpaceId, int numIterations);
984+
961985
public static native void initNativePhysics();
962986

963987
/**

jme3-jbullet/src/main/java/com/jme3/bullet/PhysicsSpace.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,22 @@ public Vector3f getWorldMax() {
875875
public void setWorldMax(Vector3f worldMax) {
876876
this.worldMax.set(worldMax);
877877
}
878+
879+
/**
880+
* Set the number of iterations used by the contact solver.
881+
*
882+
* The default is 10. Use 4 for low quality, 20 for high quality.
883+
*
884+
* @param numIterations The number of iterations used by the contact & constraint solver.
885+
*/
886+
public void setSolverNumIterations(int numIterations) {
887+
dynamicsWorld.getSolverInfo().numIterations = numIterations;
888+
}
878889

890+
public int getSolverNumIterations() {
891+
return dynamicsWorld.getSolverInfo().numIterations;
892+
}
893+
879894
/**
880895
* interface with Broadphase types
881896
*/

0 commit comments

Comments
 (0)