TestPhysicsHingeJoint does NOT show hammer node


#1

I’m on a Mac. 10.13.5
The following code, only shows hinge, not a swinging hammer node, even after pressing “H” or “K” keys.

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.input.KeyInput;
import com.jme3.input.controls.AnalogListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.shape.Sphere;

public class TestPhysicsHingeJoint extends SimpleApplication implements AnalogListener {
    private BulletAppState bulletAppState;
    private HingeJoint joint;

    public static void main(String[] args) {
        TestPhysicsHingeJoint app = new TestPhysicsHingeJoint();
        app.start();
    }

    private void setupKeys() {
        inputManager.addMapping("Left", new KeyTrigger(KeyInput.KEY_H));
        inputManager.addMapping("Right", new KeyTrigger(KeyInput.KEY_K));
        inputManager.addMapping("Swing", new KeyTrigger(KeyInput.KEY_SPACE));
        inputManager.addListener(this, "Left", "Right", "Swing");
    }

    public void onAnalog(String binding, float value, float tpf) {
        if(binding.equals("Left")){
            joint.enableMotor(true, 1, .1f);
        }
        else if(binding.equals("Right")){
            joint.enableMotor(true, -1, .1f);
        }
        else if(binding.equals("Swing")){
            joint.enableMotor(false, 0, 0);
        }
    }

    @Override
    public void simpleInitApp() {
        bulletAppState = new BulletAppState();
        stateManager.attach(bulletAppState);
        bulletAppState.setDebugEnabled(true);
        setupKeys();
        setupJoint();
    }

    private PhysicsSpace getPhysicsSpace(){
        return bulletAppState.getPhysicsSpace();
    }

    public void setupJoint() {
        Node holderNode=PhysicsTestHelper.createPhysicsTestNode(assetManager,
                new BoxCollisionShape(new Vector3f( .1f, .1f, .1f)),0);
        rootNode.attachChild(holderNode);
        getPhysicsSpace().add(holderNode);
        holderNode.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f,0,0f));

        Node hammerNode=PhysicsTestHelper.createPhysicsTestNode(assetManager,
                new BoxCollisionShape(new Vector3f( .3f, .3f, .3f)),1);
        rootNode.attachChild(hammerNode);
        getPhysicsSpace().add(hammerNode);
        hammerNode.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f,-1,0f));

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

        Geometry g = new Geometry("g1", new Sphere(10, 10, 0.2f));
        Material sphereColor = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        sphereColor.setColor("Color", ColorRGBA.LightGray);
        g.setMaterial(sphereColor);
        holderNode.attachChild(g);

        g = new Geometry("g2", new Sphere(10, 10, 0.2f));
        sphereColor = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        sphereColor.setColor("Color", ColorRGBA.Green);
        g.setMaterial(sphereColor);
        hammerNode.attachChild(g);
    }

    @Override
    public void simpleUpdate(float tpf) {

    }


}

Should it show a swinging hammer node?