PhysicsSpace: add method to set solver iterations

Thanks to Seppes (see thread: http://hub.jmonkeyengine.org/t/how-to-access-native-bullets-constraintsolver-numiterations)
experimental
Kirill Vainer 10 years ago
parent f7d544f453
commit cd1d145005
  1. 12
      jme3-bullet-native/src/native/cpp/com_jme3_bullet_PhysicsSpace.cpp
  2. 8
      jme3-bullet-native/src/native/cpp/com_jme3_bullet_PhysicsSpace.h
  3. 26
      jme3-bullet/src/main/java/com/jme3/bullet/PhysicsSpace.java
  4. 15
      jme3-jbullet/src/main/java/com/jme3/bullet/PhysicsSpace.java

@ -528,6 +528,18 @@ extern "C" {
space->getDynamicsWorld()->convexSweepTest((btConvexShape *) shape, native_from, native_to, resultCallback, native_allowed_ccd_penetration);
return;
}
JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_setSolverNumIterations
(JNIEnv *env, jobject object, jlong spaceId, jint value) {
jmePhysicsSpace* space = reinterpret_cast<jmePhysicsSpace*>(spaceId);
if (space == NULL) {
jclass newExc = env->FindClass("java/lang/NullPointerException");
env->ThrowNew(newExc, "The physics space does not exist.");
return;
}
space->getDynamicsWorld()->getSolverInfo().m_numIterations = value;
}
#ifdef __cplusplus
}

@ -174,6 +174,14 @@ JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_finalizeNative
JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_sweepTest_1native
(JNIEnv *, jobject, jlong, jobject, jobject, jlong, jobject, jfloat);
/*
* Class: com_jme3_bullet_PhysicsSpace
* Method: setSolverNumIterations
* Signature: (JI)V
*/
JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_setSolverNumIterations
(JNIEnv *, jobject, jlong, jint);
#ifdef __cplusplus
}
#endif

@ -102,6 +102,7 @@ public class PhysicsSpace {
private Vector3f worldMax = new Vector3f(10000f, 10000f, 10000f);
private float accuracy = 1f / 60f;
private int maxSubSteps = 4, rayTestFlags = 1 << 2;
private int solverNumIterations = 10;
static {
// System.loadLibrary("bulletjme");
@ -871,7 +872,7 @@ public class PhysicsSpace {
}
*/
/**
* destroys the current PhysicsSpace so that a new one can be created
*/
@ -958,6 +959,29 @@ public class PhysicsSpace {
this.worldMax.set(worldMax);
}
/**
* Set the number of iterations used by the contact solver.
*
* The default is 10. Use 4 for low quality, 20 for high quality.
*
* @param numIterations The number of iterations used by the contact & constraint solver.
*/
public void setSolverNumIterations(int numIterations) {
this.solverNumIterations = numIterations;
setSolverNumIterations(physicsSpaceId, numIterations);
}
/**
* Get the number of iterations used by the contact solver.
*
* @return The number of iterations used by the contact & constraint solver.
*/
public int getSolverNumIterations() {
return solverNumIterations;
}
private static native void setSolverNumIterations(long physicsSpaceId, int numIterations);
public static native void initNativePhysics();
/**

@ -875,7 +875,22 @@ public class PhysicsSpace {
public void setWorldMax(Vector3f worldMax) {
this.worldMax.set(worldMax);
}
/**
* Set the number of iterations used by the contact solver.
*
* The default is 10. Use 4 for low quality, 20 for high quality.
*
* @param numIterations The number of iterations used by the contact & constraint solver.
*/
public void setSolverNumIterations(int numIterations) {
dynamicsWorld.getSolverInfo().numIterations = numIterations;
}
public int getSolverNumIterations() {
return dynamicsWorld.getSolverInfo().numIterations;
}
/**
* interface with Broadphase types
*/

Loading…
Cancel
Save