Temporarily stopping the mouse from moving

If you have setUsingDelta( false ) [which is the default] that is the normal behaviour - setting mouse speed makes sense when you use the delta values.



To solve your problem simply switch off the input handler for the absolute mouse (setEnabled(false)) instead of changing speed.

irrisor said:

If you have setUsingDelta( false ) [which is the default] that is the normal behaviour - setting mouse speed makes sense when you use the delta values.

To solve your problem simply switch off the input handler for the absolute mouse (setEnabled(false)) instead of changing speed.

In my case, the input handler does more than just handling the mouse, it's much like FirstPersonHandler. Here's a quick sketch of the structure:

+


+
| MyHandler          |
+
+
  | | |
  | | +
+
  | |                                           |
  | +
+                      |
  |                      |                      |
+
+ +
+ +
+
| KeyboardLookHandler| | MouseLookHandler   | | AbsoluteMouse      |
+
+ +
+ +
+


Essentially, the MouseLookHandler will be enabled when the mouse is disabled. Am I right in that I'll need an instance of InputHandler between MyHandler and AbsoluteMouse (so that I'll be able to turn of the mouse alone, without the rest of the handlers?

Yes, instantiate a separate InputHandler for each group of actions you want to switch on and off separately. You can add the child handlers to your top level InputHandler as attached handlers to have only one InputHandler that must be updated.

Thanks a lot :slight_smile:

I tried this, but hit an interesting effect.



When I press the (middle) mouse button, the mouse stops, but when I release it, the mouse 'jumps' to where it would have moved if I would have never disabled its handler. This even happens when I set the local translation to the values stored when the button was pressed.



Here's the source code:

    public void onButton(int button, boolean pressed, int x, int y)
    {
        if(button == 2)
        {
            firstPersonHandler.getMouseLookHandler().setEnabled(pressed);
            mouseHandler.setEnabled(!pressed);
            if(pressed)
                savedMousePosition = new Vector3f(mouse.getLocalTranslation());
            else
                mouse.setLocalTranslation(savedMousePosition);
        }
    }


I tried clearActions() and removeAllActions(), and while that resulted in the mouse staying where it belonged, the mouse wasn't moveable anymore afterwards, despite being enabled again.

Did I miss something important?

We had such a bug (that mouse moving to where it would have been) in .10 - which version of jME do you use? If you use .10 using the development version (or waiting for .11) should help.

irrisor said:

We had such a bug (that mouse moving to where it would have been) in .10 - which version of jME do you use? If you use .10 using the development version (or waiting for .11) should help.

I'm using .10, so that's the problem...
Due to the proxy server / firewall combination I'm behind being very restrictive, I can't access the CVS directly or download the nightly build (the virus scanner on the proxy insists that the zip is corrupted and won't let me download). Maybe I'll find a way.

Thanks for the info, though :)

I got the nightly build, compiled it myself (ignoring any compilation errors :wink: ) and tried it. The mouse still 'jumps' after re-enabling its InputHandler, but less far and only after I move the mouse. If I just release the button, the cursor stays where it was at the time that I disabled the handler.

That behaviour is correct if you are not using deltas, because the system cursor position is still changing while the mouse is disabled. Call yourAbsoluteMouse.setUsingDeltas( true ) to have only mouse deltas used and disregard the system cursor position.

irrisor said:

That behaviour is correct if you are not using deltas, because the system cursor position is still changing while the mouse is disabled. Call yourAbsoluteMouse.setUsingDeltas( true ) to have only mouse deltas used and disregard the system cursor position.

This did the trick, even with .10 jme (which I re-extracted because the nightly build made my mouse MUCH faster).

Thanks a lot :)