Hello, I want the hammer node connected using the HingeJoint test code to hang in two cases as shown in the picture below.
As shown in the first picture, I succeeded in suspending the elongated rectangular parallelepiped, but in the second picture by rotating this node, if you were to suspend the rectangular parallelepiped 90 degrees in the Z axis, it wouldn’t work and it would continue to look like the first picture. How can we meet two cases with the same node?
package jme3test.bullet;
import com.jme3.app.SimpleApplication;
import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.PhysicsSpace;
import com.jme3.bullet.collision.shapes.BoxCollisionShape;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.bullet.joints.HingeJoint;
import com.jme3.math.FastMath;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.scene.Node;
public class TestPhysicsHingeJoint3 extends SimpleApplication {
private BulletAppState bulletAppState;
private HingeJoint joint;
public static void main(String[] args) {
TestPhysicsHingeJoint3 app = new TestPhysicsHingeJoint3();
app.start();
}
@Override
public void simpleInitApp() {
bulletAppState = new BulletAppState();
stateManager.attach(bulletAppState);
bulletAppState.setDebugEnabled(true);
bulletAppState.setDebugAxisLength(1f);
setupJoint();
flyCam.setMoveSpeed(10f);
}
private PhysicsSpace getPhysicsSpace() {
return bulletAppState.getPhysicsSpace();
}
public void setupJoint() {
/** basic code */
Node holderNode = PhysicsTestHelper.createPhysicsTestNode(assetManager,
new BoxCollisionShape(new Vector3f(.1f, .1f, .1f)), 0);
holderNode.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, 0, 0f));
rootNode.attachChild(holderNode);
getPhysicsSpace().add(holderNode);
Node hammerNode = PhysicsTestHelper.createPhysicsTestNode(assetManager,
new BoxCollisionShape(new Vector3f(.3f, .6f, .3f)), 0.001f);
hammerNode.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, 0, 0f));
hammerNode.getControl(RigidBodyControl.class).setPhysicsRotation(new Quaternion().fromAngleAxis(FastMath.HALF_PI, Vector3f.UNIT_Z));
rootNode.attachChild(hammerNode);
getPhysicsSpace().add(hammerNode);
joint = new HingeJoint(holderNode.getControl(RigidBodyControl.class),
hammerNode.getControl(RigidBodyControl.class), Vector3f.ZERO, new Vector3f(0f, -1, 0f), Vector3f.UNIT_Z,
Vector3f.UNIT_Z);
getPhysicsSpace().add(joint);
}
}
Additional explanation
I rotated the hammer node.
hammerNode.getControl(RigidBodyControl.class).setPhysicsRotation(new Quaternion().fromAngleAxis(FastMath.HALF_PI, Vector3f.UNIT_Z));