Merge pull request #303 from Dokthar/bullet_RigidBody
Bullet RigidBody : added support to vector3f based AngularFactor & LinearFactor
This commit is contained in:
commit
d1b963d843
@ -811,37 +811,70 @@ extern "C" {
|
||||
/*
|
||||
* Class: com_jme3_bullet_objects_PhysicsRigidBody
|
||||
* Method: getAngularFactor
|
||||
* Signature: (J)F
|
||||
* Signature: (JLcom/jme3/math/Vector3f;)V
|
||||
*/
|
||||
JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getAngularFactor
|
||||
(JNIEnv *env, jobject object, jlong bodyId) {
|
||||
btRigidBody* body = reinterpret_cast<btRigidBody*>(bodyId);
|
||||
if (body == NULL) {
|
||||
jclass newExc = env->FindClass("java/lang/NullPointerException");
|
||||
env->ThrowNew(newExc, "The native object does not exist.");
|
||||
return 0;
|
||||
}
|
||||
return body->getAngularFactor().getX();
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: com_jme3_bullet_objects_PhysicsRigidBody
|
||||
* Method: setAngularFactor
|
||||
* Signature: (JF)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setAngularFactor
|
||||
(JNIEnv *env, jobject object, jlong bodyId, jfloat value) {
|
||||
JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getAngularFactor
|
||||
(JNIEnv *env, jobject object, jlong bodyId, jobject factor) {
|
||||
btRigidBody* body = reinterpret_cast<btRigidBody*>(bodyId);
|
||||
if (body == NULL) {
|
||||
jclass newExc = env->FindClass("java/lang/NullPointerException");
|
||||
env->ThrowNew(newExc, "The native object does not exist.");
|
||||
return;
|
||||
}
|
||||
btVector3 vec1 = btVector3();
|
||||
vec1.setX(value);
|
||||
vec1.setY(value);
|
||||
vec1.setZ(value);
|
||||
body->setAngularFactor(vec1);
|
||||
jmeBulletUtil::convert(env, &body->getAngularFactor(), factor);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Class: com_jme3_bullet_objects_PhysicsRigidBody
|
||||
* Method: setAngularFactor
|
||||
* Signature: (JLcom/jme3/math/Vector3f;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setAngularFactor
|
||||
(JNIEnv *env, jobject object, jlong bodyId, jobject factor) {
|
||||
btRigidBody* body = reinterpret_cast<btRigidBody*>(bodyId);
|
||||
if (body == NULL) {
|
||||
jclass newExc = env->FindClass("java/lang/NullPointerException");
|
||||
env->ThrowNew(newExc, "The native object does not exist.");
|
||||
return;
|
||||
}
|
||||
btVector3 vec = btVector3();
|
||||
jmeBulletUtil::convert(env, factor, &vec);
|
||||
body->setAngularFactor(vec);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: com_jme3_bullet_objects_PhysicsRigidBody
|
||||
* Method: getLinearFactor
|
||||
* Signature: (JLcom/jme3/math/Vector3f;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getLinearFactor
|
||||
(JNIEnv *env, jobject object, jlong bodyId, jobject factor) {
|
||||
btRigidBody* body = reinterpret_cast<btRigidBody*>(bodyId);
|
||||
if (body == NULL) {
|
||||
jclass newExc = env->FindClass("java/lang/NullPointerException");
|
||||
env->ThrowNew(newExc, "The native object does not exist.");
|
||||
return;
|
||||
}
|
||||
jmeBulletUtil::convert(env, &body->getLinearFactor(), factor);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: com_jme3_bullet_objects_PhysicsRigidBody
|
||||
* Method: setLinearFactor
|
||||
* Signature: (JLcom/jme3/math/Vector3f;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setLinearFactor
|
||||
(JNIEnv *env, jobject object, jlong bodyId, jobject factor) {
|
||||
btRigidBody* body = reinterpret_cast<btRigidBody*>(bodyId);
|
||||
if (body == NULL) {
|
||||
jclass newExc = env->FindClass("java/lang/NullPointerException");
|
||||
env->ThrowNew(newExc, "The native object does not exist.");
|
||||
return;
|
||||
}
|
||||
btVector3 vec = btVector3();
|
||||
jmeBulletUtil::convert(env, factor, &vec);
|
||||
body->setLinearFactor(vec);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -396,18 +396,35 @@ JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getAngula
|
||||
/*
|
||||
* Class: com_jme3_bullet_objects_PhysicsRigidBody
|
||||
* Method: getAngularFactor
|
||||
* Signature: (J)F
|
||||
* Signature: (JLcom/jme3/math/Vector3f;)V
|
||||
*/
|
||||
JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getAngularFactor
|
||||
(JNIEnv *, jobject, jlong);
|
||||
JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getAngularFactor
|
||||
(JNIEnv *, jobject, jlong, jobject);
|
||||
|
||||
|
||||
/*
|
||||
* Class: com_jme3_bullet_objects_PhysicsRigidBody
|
||||
* Method: setAngularFactor
|
||||
* Signature: (JF)V
|
||||
* Signature: (JLcom/jme3/math/Vector3f;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setAngularFactor
|
||||
(JNIEnv *, jobject, jlong, jfloat);
|
||||
(JNIEnv *, jobject, jlong, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jme3_bullet_objects_PhysicsRigidBody
|
||||
* Method: getLinearFactor
|
||||
* Signature: (JLcom/jme3/math/Vector3f;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getLinearFactor
|
||||
(JNIEnv *, jobject, jlong, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jme3_bullet_objects_PhysicsRigidBody
|
||||
* Method: setLinearFactor
|
||||
* Signature: (JLcom/jme3/math/Vector3f;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setLinearFactor
|
||||
(JNIEnv *, jobject, jlong, jobject);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -627,16 +627,44 @@ public class PhysicsRigidBody extends PhysicsCollisionObject {
|
||||
private native float getAngularSleepingThreshold(long objectId);
|
||||
|
||||
public float getAngularFactor() {
|
||||
return getAngularFactor(objectId);
|
||||
return getAngularFactor(null).getX();
|
||||
}
|
||||
|
||||
private native float getAngularFactor(long objectId);
|
||||
public Vector3f getAngularFactor(Vector3f store) {
|
||||
// doing like this prevent from breaking the API
|
||||
if (store == null) {
|
||||
store = new Vector3f();
|
||||
}
|
||||
getAngularFactor(objectId, store);
|
||||
return store;
|
||||
}
|
||||
|
||||
private native void getAngularFactor(long objectId, Vector3f vec);
|
||||
|
||||
public void setAngularFactor(float factor) {
|
||||
setAngularFactor(objectId, new Vector3f(factor, factor, factor));
|
||||
}
|
||||
|
||||
public void setAngularFactor(Vector3f factor) {
|
||||
setAngularFactor(objectId, factor);
|
||||
}
|
||||
|
||||
private native void setAngularFactor(long objectId, float factor);
|
||||
private native void setAngularFactor(long objectId, Vector3f factor);
|
||||
|
||||
public Vector3f getLinearFactor() {
|
||||
Vector3f vec = new Vector3f();
|
||||
getLinearFactor(objectId, vec);
|
||||
return vec;
|
||||
}
|
||||
|
||||
private native void getLinearFactor(long objectId, Vector3f vec);
|
||||
|
||||
public void setLinearFactor(Vector3f factor) {
|
||||
setLinearFactor(objectId, factor);
|
||||
}
|
||||
|
||||
private native void setLinearFactor(long objectId, Vector3f factor);
|
||||
|
||||
|
||||
/**
|
||||
* do not use manually, joints are added automatically
|
||||
@ -673,7 +701,13 @@ public class PhysicsRigidBody extends PhysicsCollisionObject {
|
||||
capsule.write(getGravity(), "gravity", Vector3f.ZERO);
|
||||
capsule.write(getFriction(), "friction", 0.5f);
|
||||
capsule.write(getRestitution(), "restitution", 0);
|
||||
Vector3f angularFactor = getAngularFactor(null);
|
||||
if (angularFactor.x == angularFactor.y && angularFactor.y == angularFactor.z) {
|
||||
capsule.write(getAngularFactor(), "angularFactor", 1);
|
||||
} else {
|
||||
capsule.write(getAngularFactor(null), "angularFactor", Vector3f.UNIT_XYZ);
|
||||
capsule.write(getLinearFactor(), "linearFactor", Vector3f.UNIT_XYZ);
|
||||
}
|
||||
capsule.write(kinematic, "kinematic", false);
|
||||
|
||||
capsule.write(getLinearDamping(), "linearDamping", 0);
|
||||
@ -703,7 +737,13 @@ public class PhysicsRigidBody extends PhysicsCollisionObject {
|
||||
setKinematic(capsule.readBoolean("kinematic", false));
|
||||
|
||||
setRestitution(capsule.readFloat("restitution", 0));
|
||||
Vector3f angularFactor = (Vector3f) capsule.readSavable("angularFactor", Vector3f.NAN.clone());
|
||||
if(angularFactor == Vector3f.NAN) {
|
||||
setAngularFactor(capsule.readFloat("angularFactor", 1));
|
||||
} else {
|
||||
setAngularFactor(angularFactor);
|
||||
setLinearFactor((Vector3f) capsule.readSavable("linearFactor", Vector3f.UNIT_XYZ.clone()));
|
||||
}
|
||||
setDamping(capsule.readFloat("linearDamping", 0), capsule.readFloat("angularDamping", 0));
|
||||
setSleepingThresholds(capsule.readFloat("linearSleepingThreshold", 0.8f), capsule.readFloat("angularSleepingThreshold", 1.0f));
|
||||
setCcdMotionThreshold(capsule.readFloat("ccdMotionThreshold", 0));
|
||||
|
Loading…
x
Reference in New Issue
Block a user