From 96b355e38c7bec1d20b8074e1e14a9035bfcd35e Mon Sep 17 00:00:00 2001 From: Kai Boernert Date: Thu, 10 Aug 2017 14:06:44 +0200 Subject: [PATCH] added inertia manipulating methods --- ...m_jme3_bullet_objects_PhysicsRigidBody.cpp | 35 +++++++++++++++++++ ...com_jme3_bullet_objects_PhysicsRigidBody.h | 8 +++++ .../jme3/bullet/objects/PhysicsRigidBody.java | 16 ++++++++- 3 files changed, 58 insertions(+), 1 deletion(-) diff --git a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_PhysicsRigidBody.cpp b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_PhysicsRigidBody.cpp index 9241bcf5b..465c15620 100644 --- a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_PhysicsRigidBody.cpp +++ b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_PhysicsRigidBody.cpp @@ -151,6 +151,41 @@ extern "C" { // } } + + /* + * Class: com_jme3_bullet_objects_PhysicsRigidBody + * Method: setInverseInertiaLocal + * Signature: (JLcom/jme3/math/Vector3f;)V + */ + JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setInverseInertiaLocal + (JNIEnv *env, jobject object, jlong bodyId, jobject value) { + btRigidBody* body = reinterpret_cast(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, value, &vec); + body->setInvInertiaDiagLocal(vec); + } + + /* + * Class: com_jme3_bullet_objects_PhysicsRigidBody + * Method: getInverseInertiaLocal + * Signature: (JLcom/jme3/math/Vector3f;)V + */ + JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getInverseInertiaLocal + (JNIEnv *env, jobject object, jlong bodyId, jobject value) { + btRigidBody* body = reinterpret_cast(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->getInvInertiaDiagLocal(), value); + } + /* * Class: com_jme3_bullet_objects_PhysicsRigidBody * Method: getPhysicsLocation diff --git a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_PhysicsRigidBody.h b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_PhysicsRigidBody.h index 4cfb85b37..273c4c7f7 100644 --- a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_PhysicsRigidBody.h +++ b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_PhysicsRigidBody.h @@ -89,6 +89,14 @@ JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setPhysicsR JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getPhysicsLocation (JNIEnv *, jobject, jlong, jobject); +/* + * Class: com_jme3_bullet_objects_PhysicsRigidBody + * Method: getInverseInertiaLocal + * Signature: (JLcom/jme3/math/Vector3f;)V + */ +JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getInverseInertiaLocal + (JNIEnv *, jobject, jlong, jobject); + /* * Class: com_jme3_bullet_objects_PhysicsRigidBody * Method: getPhysicsRotation diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsRigidBody.java b/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsRigidBody.java index 0342f4c77..84c16f831 100644 --- a/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsRigidBody.java +++ b/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsRigidBody.java @@ -185,6 +185,21 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { getPhysicsRotation(objectId, rot); return rot; } + + public void setInverseInertiaLocal(Vector3f gravity) { + setInverseInertiaLocal(objectId, gravity); + } + private native void setInverseInertiaLocal(long objectId, Vector3f gravity); + + public Vector3f getInverseInertiaLocal(Vector3f trans) { + if (trans == null) { + trans = new Vector3f(); + } + getInverseInertiaLocal(objectId, trans); + return trans; + } + + private native void getInverseInertiaLocal(long objectId, Vector3f vector); private native void getPhysicsRotation(long objectId, Quaternion rot); @@ -352,7 +367,6 @@ public class PhysicsRigidBody extends PhysicsCollisionObject { public void setGravity(Vector3f gravity) { setGravity(objectId, gravity); } - private native void setGravity(long objectId, Vector3f gravity); public float getFriction() {