Skip to content

Commit

Permalink
Point2PointJoint: add getters and setters for the pivot locations
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Feb 20, 2021
1 parent f3833d4 commit 6876219
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 0 deletions.
61 changes: 61 additions & 0 deletions src/main/java/com/jme3/bullet/joints/Point2PointJoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.jme3.math.Transform;
import com.jme3.math.Vector3f;
import java.util.logging.Logger;
import jme3utilities.Validate;

/**
* A 3 degree-of-freedom joint based on Bullet's btPoint2PointConstraint.
Expand Down Expand Up @@ -136,6 +137,34 @@ public float getImpulseClamp() {
return getImpulseClamp(constraintId);
}

/**
* Locate the pivot in A's scaled local coordinates.
*
* @param storeResult storage for the result (modified if not null)
* @return the pivot location (either storeResult or a new vector, not null)
*/
public Vector3f getPivotInA(Vector3f storeResult) {
Vector3f result = (storeResult == null) ? new Vector3f() : storeResult;
long constraintId = nativeId();
getPivotInA(constraintId, result);

return result;
}

/**
* Locate the pivot in B's scaled local coordinates.
*
* @param storeResult storage for the result (modified if not null)
* @return the pivot location (either storeResult or a new vector, not null)
*/
public Vector3f getPivotInB(Vector3f storeResult) {
Vector3f result = storeResult == null ? new Vector3f() : storeResult;
long constraintId = nativeId();
getPivotInB(constraintId, result);

return result;
}

/**
* Read the joint's tau value.
*
Expand Down Expand Up @@ -167,6 +196,30 @@ public void setImpulseClamp(float value) {
setImpulseClamp(constraintId, value);
}

/**
* Alter the pivot location in A's scaled local coordinates.
*
* @param location the desired location (not null, unaffected)
*/
public void setPivotInA(Vector3f location) {
Validate.nonNull(location, "location");

long constraintId = nativeId();
setPivotInA(constraintId, location);
}

/**
* Alter the pivot location in B's scaled local coordinates.
*
* @param location the desired location (not null, unaffected)
*/
public void setPivotInB(Vector3f location) {
Validate.nonNull(location, "location");

long constraintId = nativeId();
setPivotInB(constraintId, location);
}

/**
* Alter the joint's tau value.
*
Expand Down Expand Up @@ -241,12 +294,20 @@ native private static long createJoint(long bodyIdA, long bodyIdB,

native private static float getImpulseClamp(long jointId);

native private static void getPivotInA(long jointId, Vector3f storeVector);

native private static void getPivotInB(long jointId, Vector3f storeVector);

native private static float getTau(long jointId);

native private static void setDamping(long jointId, float desiredDamping);

native private static void setImpulseClamp(long jointId,
float desiredClamp);

native private static void setPivotInA(long jointId, Vector3f pivotInA);

native private static void setPivotInB(long jointId, Vector3f pivotInB);

native private static void setTau(long jointId, float desiredTau);
}
70 changes: 70 additions & 0 deletions src/main/native/glue/com_jme3_bullet_joints_Point2PointJoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,40 @@ JNIEXPORT jfloat JNICALL Java_com_jme3_bullet_joints_Point2PointJoint_getImpulse
return pJoint->m_setting.m_impulseClamp;
}

/*
* Class: com_jme3_bullet_joints_Point2PointJoint
* Method: getPivotInA
* Signature: (JLcom/jme3/math/Vector3f;)V
*/
JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_Point2PointJoint_getPivotInA
(JNIEnv *pEnv, jclass, jlong jointId, jobject storeVector) {
btPoint2PointConstraint *pJoint
= reinterpret_cast<btPoint2PointConstraint *> (jointId);
NULL_CHK(pEnv, pJoint, "The btPoint2PointConstraint does not exist.",)
btAssert(pJoint->getConstraintType() == POINT2POINT_CONSTRAINT_TYPE);
NULL_CHK(pEnv, storeVector, "The store vector does not exist.",);

const btVector3& location = pJoint->getPivotInA();
jmeBulletUtil::convert(pEnv, &location, storeVector);
}

/*
* Class: com_jme3_bullet_joints_Point2PointJoint
* Method: getPivotInB
* Signature: (JLcom/jme3/math/Vector3f;)V
*/
JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_Point2PointJoint_getPivotInB
(JNIEnv *pEnv, jclass, jlong jointId, jobject storeVector) {
btPoint2PointConstraint *pJoint
= reinterpret_cast<btPoint2PointConstraint *> (jointId);
NULL_CHK(pEnv, pJoint, "The btPoint2PointConstraint does not exist.",)
btAssert(pJoint->getConstraintType() == POINT2POINT_CONSTRAINT_TYPE);
NULL_CHK(pEnv, storeVector, "The store vector does not exist.",);

const btVector3& location = pJoint->getPivotInB();
jmeBulletUtil::convert(pEnv, &location, storeVector);
}

/*
* Class: com_jme3_bullet_joints_Point2PointJoint
* Method: getTau
Expand Down Expand Up @@ -167,6 +201,42 @@ JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_Point2PointJoint_setImpulseCl
pJoint->m_setting.m_impulseClamp = clamp;
}

/*
* Class: com_jme3_bullet_joints_Point2PointJoint
* Method: setPivotInA
* Signature: (JLcom/jme3/math/Vector3f;)V
*/
JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_Point2PointJoint_setPivotInA
(JNIEnv *pEnv, jclass, jlong jointId, jobject locationVector) {
btPoint2PointConstraint *pJoint
= reinterpret_cast<btPoint2PointConstraint *> (jointId);
NULL_CHK(pEnv, pJoint, "The btPoint2PointConstraint does not exist.",)
btAssert(pJoint->getConstraintType() == POINT2POINT_CONSTRAINT_TYPE);
NULL_CHK(pEnv, locationVector, "The location vector does not exist.",);

btVector3 pivot;
jmeBulletUtil::convert(pEnv, locationVector, &pivot);
pJoint->setPivotA(pivot);
}

/*
* Class: com_jme3_bullet_joints_Point2PointJoint
* Method: setPivotInB
* Signature: (JLcom/jme3/math/Vector3f;)V
*/
JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_Point2PointJoint_setPivotInB
(JNIEnv *pEnv, jclass, jlong jointId, jobject locationVector) {
btPoint2PointConstraint *pJoint
= reinterpret_cast<btPoint2PointConstraint *> (jointId);
NULL_CHK(pEnv, pJoint, "The btPoint2PointConstraint does not exist.",)
btAssert(pJoint->getConstraintType() == POINT2POINT_CONSTRAINT_TYPE);
NULL_CHK(pEnv, locationVector, "The location vector does not exist.",);

btVector3 pivot;
jmeBulletUtil::convert(pEnv, locationVector, &pivot);
pJoint->setPivotB(pivot);
}

/*
* Class: com_jme3_bullet_joints_Point2PointJoint
* Method: setTau
Expand Down
32 changes: 32 additions & 0 deletions src/main/native/glue/com_jme3_bullet_joints_Point2PointJoint.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6876219

Please sign in to comment.