Node rotation is initialized when using HingeJoint

Hello, I want the hammer node connected using the HingeJoint test code to hang in two cases as shown in the picture below.

rotation

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));

That’s how physics works. The hammer will always try to fall and thus always end up vertical, no matter what rotation it starts at.

If you really don’t want it to rotate, you can try…

hammerNode.getControl(RigidBodyControl.class).setAngularFactor(0f);

…which will “disable” angular momentum (or physics rotation) for that rigid body.

1 Like

Thank you for your answer. I don’t think this is the result I want. I explained it wrong. I want the local coordinates to be maintained even if the object rotates

1 Like

That could mean a number of things, but I’m assuming you want hammer node’s children to maintain their local coordinates even if the parent is rotating. There is no way to do exactly that, since all children share their parent’s transform, no exceptions.

If you want one spatial to match another spatial’s translation, but be independent in all other senses, try:

spatial1.setLocalTranslation(spatial2.getLocalTranslation());

and do not attach the two spatials together.

1 Like

Does the following video approximate the effect you’re trying to achieve?

Note: for reasons I don’t understand, YouTube blurs the first 15-20 seconds.

2 Likes

There is no way to do exactly that, since all children share their parent’s transform, no exceptions.

I don’t think I can use the way I want to I’ll find another way

Thank you, but I don’t think that’s what I want because there’s no running collision inside

I think this is just you. A local phenomena. Even YouTube says it is doing HD, it is not yet doing that. It is still sniffing etc. Even with supposedly fast networks this happens to me. If I manually select the quality at the start, then I get it without the initial blurring. Seems to be just the algorithm YouTube uses…

1 Like

I was able to specify “1080p60” in the settings, and that solved the playback issue for me. Thanks for the tip!

1 Like

Please clarify what you want, then. I don’t understand what you mean by a “running collision inside”.