Skip to content

Commit

Permalink
Anchor: add the setPivotInB() method
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Nov 8, 2021
1 parent fc7440d commit c54437a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
17 changes: 16 additions & 1 deletion src/main/java/com/jme3/bullet/joints/Anchor.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,23 @@ public int nodeIndex() {
public void setInfluence(float amount) {
Validate.fraction(amount, "amount");

long anchorId = nativeId();
this.influence = amount;
long anchorId = nativeId();
setInfluence(anchorId, amount);
}

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

pivotInB.set(location);
long archorId = nativeId();
setPivotInB(archorId, location);
}
// *************************************************************************
// PhysicsJoint methods

Expand Down Expand Up @@ -230,4 +243,6 @@ native private static long createAnchor(long softBodyId, int nodeIndex,
float influence);

native private static void setInfluence(long anchorId, float influence);

native private static void setPivotInB(long anchorId, Vector3f location);
}
17 changes: 16 additions & 1 deletion src/main/native/glue/com_jme3_bullet_joints_Anchor.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2020 jMonkeyEngine
* Copyright (c) 2019-2021 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -82,3 +82,18 @@ JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_Anchor_setInfluence

pAnchor->m_influence = (btScalar) influence;
}

/*
* Class: com_jme3_bullet_joints_Anchor
* Method: setPivotInB
* Signature: (JLcom/jme3/math/Vector3f;)V
*/
JNIEXPORT void JNICALL Java_com_jme3_bullet_joints_Anchor_setPivotInB
(JNIEnv *pEnv, jclass, jlong anchorId, jobject locationVector) {
btSoftBody::Anchor *pAnchor
= reinterpret_cast<btSoftBody::Anchor *> (anchorId);
NULL_CHK(pEnv, pAnchor, "The btSoftBody::Anchor does not exist.",)
NULL_CHK(pEnv, locationVector, "The location vector does not exist.",)

jmeBulletUtil::convert(pEnv, locationVector, &pAnchor->m_local);
}
8 changes: 8 additions & 0 deletions src/main/native/glue/com_jme3_bullet_joints_Anchor.h

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

0 comments on commit c54437a

Please sign in to comment.