Disable Mouse Move

Is there any easy way to disable the camera movement? When you create the model, if you move the mouse, the model rotates around the camera. How can you disable that? :?

The camera is rotated by the FirstPersonHandler created in SimpleGame. You can replace it by calling

input = new InputHandler();


At the beginning of your simpleInitGame method. Note that this also replaces other input stuff initialized in SimpleGame.

Here's my class which does all the input handling. Maybe you can reuse parts of it.


package com.necro.gui.input;

import com.jme.input.AbsoluteMouse;
import com.jme.input.FirstPersonHandler;
import com.jme.input.InputHandler;
import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput;
import com.jme.input.MouseInput;
import com.jme.input.MouseInputListener;
import com.jme.input.action.InputActionEvent;
import com.jme.input.action.KeyBackwardAction;
import com.jme.input.action.KeyForwardAction;
import com.jme.input.action.KeyStrafeDownAction;
import com.jme.input.action.KeyStrafeUpAction;
import com.jme.math.Vector3f;
import com.jme.renderer.Camera;
import com.necro.gui.GUI;
import com.necro.gui.manager.GUIManager;
import com.necro.gui.manager.StateManager;

public class Input extends InputHandler implements MouseInputListener
{
    private GUIManager manager;
    private FirstPersonHandler firstPersonHandler;
    private InputHandler mouseHandler;
    private AbsoluteMouse mouse;
    private boolean isLeftClick, isRightClick;

    private KeyForwardAction forward;
    private KeyBackwardAction backward;
    private float wheelSpeed;

    public Input(GUIManager manager, GUI gui, float moveSpeed, float turnSpeed)
    {
        this.manager = manager;
        KeyBindingManager keyboard = KeyBindingManager.getKeyBindingManager();

        firstPersonHandler = new FirstPersonHandler(gui.getCamera(), moveSpeed, turnSpeed);
        addToAttachedHandlers(firstPersonHandler);
        firstPersonHandler.getMouseLookHandler().setEnabled(false);

        mouse = new AbsoluteMouse("The Mouse", gui.getWidth(), gui.getHeight());
        mouse.setLocalTranslation(new Vector3f(gui.getWidth() / 2, gui.getHeight() / 2, 0));
        mouse.setRenderState(StateManager.getAlphaState());
        mouse.setRenderState(StateManager.getTextureState("cursor"));
        mouse.setUsingDelta(true);

        mouseHandler = new InputHandler();
        addToAttachedHandlers(mouseHandler);
        mouse.registerWithInputHandler(mouseHandler);
        MouseInput.get().addListener(this);
        wheelSpeed = moveSpeed;

        keyboard.set("strafeUp", KeyInput.KEY_R);
        keyboard.set("strafeDown", KeyInput.KEY_F);

        addAction(new KeyStrafeUpAction(gui.getCamera(), moveSpeed), "strafeUp", true);
        addAction(new KeyStrafeDownAction(gui.getCamera(), moveSpeed), "strafeDown", true);

        forward = new KeyForwardAction(gui.getCamera(), moveSpeed);
        backward = new KeyBackwardAction(gui.getCamera(), moveSpeed);
    }

    public AbsoluteMouse getMouse()
    {
        return mouse;
    }

    public void onButton(int button, boolean pressed, int x, int y)
    {
        if(button == 0) // Left mouse button
        {
            if(pressed)
                isLeftClick = true;
            else if(isLeftClick)
                manager.onClick(button, x, y);
        }
        else if(button == 1) // Right mouse button
        {
            if(pressed)
                isRightClick = true;
            else if(isRightClick)
                System.out.println("Right click!");
        }
        else if(button == 2) // Middle mouse button
        {
            firstPersonHandler.getMouseLookHandler().setEnabled(pressed);
            mouseHandler.setEnabled(!pressed);
        }
    }

    public void onWheel(int wheelDelta, int x, int y)
    {
        InputActionEvent eve = new InputActionEvent();

        if(wheelDelta > 0)
        {
            eve.setTime(wheelDelta / 1000.0f);
            forward.performAction(eve);
        }
        else
        {
            eve.setTime(wheelDelta / 1000.0f * -1);
            backward.performAction(eve);
        }
    }

    public void onMove(int xDelta, int yDelta, int newX, int newY)
    {
        isLeftClick = isRightClick = false;
    }
}