diff --git a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_joints_SixDofJoint.cpp b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_joints_SixDofJoint.cpp index ea55820e0..24a26c0cf 100644 --- a/jme3-bullet-native/src/native/cpp/com_jme3_bullet_joints_SixDofJoint.cpp +++ b/jme3-bullet-native/src/native/cpp/com_jme3_bullet_joints_SixDofJoint.cpp @@ -165,6 +165,30 @@ extern "C" { btGeneric6DofConstraint* joint = new btGeneric6DofConstraint(*bodyA, *bodyB, transA, transB, useLinearReferenceFrameA); return reinterpret_cast(joint); } + + /* + * Class: com_jme3_bullet_joints_SixDofJoint + * Method: getAngles + * Signature: (JLcom/jme3/math/Vector3f;)V + */ + JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_SixDofJoint_getAngles + (JNIEnv *env, jobject object, jlong jointId, jobject storeVector) { + btGeneric6DofConstraint *pJoint + = reinterpret_cast (jointId); + if (pJoint == NULL) { + jclass newExc = env->FindClass("java/lang/NullPointerException"); + env->ThrowNew(newExc, "The native object does not exist."); + return; + } + + pJoint->calculateTransforms(); + btScalar x = pJoint->getAngle(0); + btScalar y = pJoint->getAngle(1); + btScalar z = pJoint->getAngle(2); + const btVector3& angles = btVector3(x, y, z); + jmeBulletUtil::convert(env, &angles, storeVector); + } + #ifdef __cplusplus } #endif diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/joints/SixDofJoint.java b/jme3-bullet/src/main/java/com/jme3/bullet/joints/SixDofJoint.java index 74ab70cbc..27e4c48b9 100644 --- a/jme3-bullet/src/main/java/com/jme3/bullet/joints/SixDofJoint.java +++ b/jme3-bullet/src/main/java/com/jme3/bullet/joints/SixDofJoint.java @@ -166,6 +166,24 @@ public class SixDofJoint extends PhysicsJoint { translationalMotor = new TranslationalLimitMotor(getTranslationalLimitMotor(objectId)); } + native private void getAngles(long jointId, Vector3f storeVector); + + /** + * Copy the joint's rotation angles. + * + * @param storeResult storage for the result (modified if not null) + * @return the rotation angle for each local axis (in radians, either + * storeResult or a new vector, not null) + */ + public Vector3f getAngles(Vector3f storeResult) { + Vector3f result = (storeResult == null) ? new Vector3f() : storeResult; + + long constraintId = getObjectId(); + getAngles(constraintId, result); + + return result; + } + private native long getRotationalLimitMotor(long objectId, int index); private native long getTranslationalLimitMotor(long objectId);