1

Normally the mouse is locked to the window and is not visible; controlling the camera in the style of first person shooters.

My understanding is you unlocking the mouse from a JMonkey window and make it visible by calling

inputManager.setCursorVisible(true);

However this has no visible effect. This is demonstrated within the following example program:

public class Main extends SimpleApplication {

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

    @Override
    public void simpleInitApp() {
        Box b = new Box(Vector3f.ZERO, 1, 1, 1);
        Geometry geom = new Geometry("Box", b);

        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        mat.setColor("Color", ColorRGBA.Blue);
        geom.setMaterial(mat);
        inputManager.setCursorVisible(true);

        rootNode.attachChild(geom);
    }

}

Calling flyCam.setDragToRotate(true); unlocks the mouse but also causes a number of DragToRotate behaviours (unsurpisingly)

Richard Tingle
  • 16,906
  • 5
  • 52
  • 77

3 Answers3

1

The solution to this seems to be that the flycam must also be disabled. So

inputManager.setCursorVisible(true);
flyCam.setEnabled(false);

Or as a full example

public class Main extends SimpleApplication {

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

    @Override
    public void simpleInitApp() {
        Box b = new Box(Vector3f.ZERO, 1, 1, 1);
        Geometry geom = new Geometry("Box", b);

        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        mat.setColor("Color", ColorRGBA.Blue);
        geom.setMaterial(mat);
        inputManager.setCursorVisible(true);
        flyCam.setEnabled(false);
        //flyCam.setDragToRotate(true);
        inputManager.setCursorVisible(true);
        rootNode.attachChild(geom);
    }

}
Richard Tingle
  • 16,906
  • 5
  • 52
  • 77
1

Disabling the FlyCam is one way to do this, but a better way is never to add it in the first place. If you create a new constructor for your app and call the second constructor for SimpleApplication you can pass in a list of Application States to use and these completely replace the standard set so you can pick exactly which ones you want.

Tim B
  • 40,716
  • 16
  • 83
  • 128
  • For my use case I need to move between modes so I need it sometimes. This may be useful for other cases however – Richard Tingle Jan 04 '14 at 20:57
  • You can add and remove app states dynamically, but yes in your case you may be better off just enabling and disabling it as required. – Tim B Jan 04 '14 at 21:07
-1

Or simply:

flyCam.setDragToRotate(true);

inputManager.setCursorVisible(true);

The flyCam can still be on

demongolem
  • 9,474
  • 36
  • 90
  • 105
  • This works, but causes the dragToRotate behaviour to kick in. Specifically if you have any "click and drag" behaviour then it doesn't work properly – Richard Tingle Mar 28 '14 at 17:34