How to switch mouse control into/outof a Canvas or RenderWindow

Hello,



I need a little help to solve a problem. Imagine this:

You have either a normal render window or a swing app with a canvas for jME rendering.

The goal would be, to use a Mouse either in the jME scene in a way that is similar to the normal RelativeMouse or in the swing app to make GUI actions on the other elements outside the jME-canvas.

For example, if the user makes a click or double click on the canvas, the mouse will be a controler for the camera viewing direction in the scene.

If the user later presses <ESC>, he will have the normal mouse for interaction with the swing app.



None of the demos in jmetest has such a mechanism and I do not know how to do this by myself.

Maybe I would just need a little hint on which general steps would be necessary to achieve the mentioned goal.



Thank you for any help

I know you can use mouse arrow with this:

MouseInput.get().setCursorVisible(true);


hope this helps, I use it to interact with popup options menu in my game.

I think what you want is to toggle between absolute mouse and mouse look. To achieve that I use:


   public void setupMouse(boolean what) {
      isMouseLook = what;
      if (isMouseLook) {
         absoluteMouse.registerWithInputHandler(null);
         absoluteMouse.setCullMode(Spatial.CULL_ALWAYS);
         input.getMouseLookHandler().setEnabled(true);
      } else {
         absoluteMouse.registerWithInputHandler(input);
         absoluteMouse.setCullMode(Spatial.CULL_NEVER);
         input.getMouseLookHandler().setEnabled(false);
      }
   }



If you call this with what=true you will get mouselook mode, false means absolute mouse. The call to setCullMode () is only needed if you use a custom cursor. Otherwise use the MouseInput.get().setCursorVisible(true) as mentioned by mud2005.

hm, thank you guys, but that didn't help.



@Galun: I tried the code you posted (modified it, since I do not use a standard FirstPersonHandler) - but didn't work.



The general problem is that I need the mouse to "leave" the render window - like with a swing canvas.

But when the user clicks on that "canvas", the control should be like with a normal mouse look.



It seems that both possibilities end in a dead road:

  1. leave render window (only works with ALT+TAB on windows) -> possible at all?
  2. use a SimpleCanvasImpl and try to catch the mouse -> do not know how to make it / possible at all?





    But it's ok, since I do not work on the project that does need this type of input handling anymore.

    You can expect to see other interesting work from me soon (maybe in the user showcase).