2
0
Эх сурвалжийг харах

Bullet PhysicsRigigBody : added set/getAngularFactor(Vector3f) and set/getLinearFactor(Vector3f), these methods are usefull for locking axis translations or rotation

Maselbas 10 жил өмнө
parent
commit
878f2cbbbc

+ 57 - 5
jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_PhysicsRigidBody.cpp

@@ -811,17 +811,17 @@ 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) {
+    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 0;
+            return;
         }
-        return body->getAngularFactor().getX();
+        jmeBulletUtil::convert(env, &body->getAngularFactor(), factor);
     }
 
     /*
@@ -844,6 +844,58 @@ extern "C" {
         body->setAngularFactor(vec1);
     }
 
+    /*
+     * 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
 }
 #endif

+ 27 - 3
jme3-bullet-native/src/native/cpp/com_jme3_bullet_objects_PhysicsRigidBody.h

@@ -396,10 +396,10 @@ 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
@@ -409,6 +409,30 @@ JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_getAngula
 JNIEXPORT void JNICALL Java_com_jme3_bullet_objects_PhysicsRigidBody_setAngularFactor
   (JNIEnv *, jobject, jlong, jfloat);
 
+/*
+ * 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 *, 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
 }
 #endif

+ 30 - 5
jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsRigidBody.java

@@ -626,11 +626,13 @@ public class PhysicsRigidBody extends PhysicsCollisionObject {
 
     private native float getAngularSleepingThreshold(long objectId);
 
-    public float getAngularFactor() {
-        return getAngularFactor(objectId);
+    public Vector3f getAngularFactor() {
+        Vector3f vec = new Vector3f();
+        getAngularFactor(objectId, vec);
+	return vec;
     }
 
-    private native float getAngularFactor(long objectId);
+    private native void getAngularFactor(long objectId, Vector3f vec);
 
     public void setAngularFactor(float factor) {
         setAngularFactor(objectId, factor);
@@ -638,6 +640,27 @@ public class PhysicsRigidBody extends PhysicsCollisionObject {
 
     private native void setAngularFactor(long objectId, float factor);
 
+    public void setAngularFactor(Vector3f factor) {
+	setAngularFactor(objectId, 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 +696,8 @@ public class PhysicsRigidBody extends PhysicsCollisionObject {
         capsule.write(getGravity(), "gravity", Vector3f.ZERO);
         capsule.write(getFriction(), "friction", 0.5f);
         capsule.write(getRestitution(), "restitution", 0);
-        capsule.write(getAngularFactor(), "angularFactor", 1);
+        capsule.write(getAngularFactor(), "angularFactor", Vector3f.UNIT_XYZ);
+        capsule.write(getLinearFactor(), "linearFactor", Vector3f.UNIT_XYZ);
         capsule.write(kinematic, "kinematic", false);
 
         capsule.write(getLinearDamping(), "linearDamping", 0);
@@ -703,7 +727,8 @@ public class PhysicsRigidBody extends PhysicsCollisionObject {
         setKinematic(capsule.readBoolean("kinematic", false));
 
         setRestitution(capsule.readFloat("restitution", 0));
-        setAngularFactor(capsule.readFloat("angularFactor", 1));
+        setAngularFactor((Vector3f) capsule.readSavable("angularFactor", Vector3f.UNIT_XYZ.clone()));
+        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));