Relative, absolute mouse and JMEDesktop

Hello,



I would like to combine mouse look mode and an absolute mouse (toggle with middle mouse button) and JMEDesktop.

This works as long as I use the system mouse cursor. Now I tried to implement a custom cursor and got totally lost. The source is a mess due to various tests.

Could you give me some hints on how this can be achieved?

You can use MouseLook and AbsoluteMouse. Just call setUsingDelta( false ) on your absolute mouse to make it work with JMEDesktop as well.

Well, mixing AbsoluteMouse and RelativeMouse works for me if I don't use a custom cursor. The problem I have is that either a custom cursor and the system cursor is visible or the control in mouse look goes nuts if I try to replace the system cursor with a custom one.



I think I should post the relavant code fragments but this is not so easy as the code base starts to get big (99 files, 12642 lines). sigh

i hope the "relavant code fragments" is not spread out on those 99 files  :smiley:

They are not spread over all sources, no :slight_smile: Ok, I'll try.



The game (class Cient) is extending BaseGame. I implemented custom handlers because I had to restrict the look up and down angles.



initSystem() in Client:


      input = new WomInputHandler(this, cam, Config.getRenderer());
      input.getKeyboardLookHandler().setActionSpeed(Config.KEYSPEED);
      input.getMouseLookHandler().setActionSpeed(Config.MOUSESPEED);



initGame() in Client (the input handler in ClientGui is forwarded to a JMEDesktop):


      gui = new ClientGui(display, cam, input);
      gui.setRootNode(rootNode);
      gui.initialize();
      desktop = gui.getDesktop();
      desktop.setClickListener(new GuiClickListener());
      desktop.setChatListener(new ChatListener());



onMouseButtonClicked() in Client:


   public void onMouseButtonClicked(int button) {
      Node inTarget;

      if (button == 3) {
         if (mouseLook) {
            mouseLook = false;
            desktop.setFocus("status");
         } else {
            mouseLook = true;
         }
         return;
      }

      if (! mouseLook)
         return;



the custom input handler:


package de.worldofmystery.client.input;

import java.util.logging.Logger;

import com.jme.app.AbstractGame;
import com.jme.input.InputHandler;
import com.jme.input.KeyBindingManager;
import com.jme.input.MouseInput;
import com.jme.input.MouseLookHandler;
import com.jme.renderer.Camera;
import com.jme.util.LoggingSystem;


public class WomInputHandler extends InputHandler
{
   Logger _log = LoggingSystem.getLogger();
   
   KeyBindingManager keyboard = KeyBindingManager.getKeyBindingManager();

This is from the Gui and the desktop class:


   public ClientGui(DisplaySystem display, Camera cam, WomInputHandler input) {
      this.display = display;
      this.cam = cam;
      this.input = input;
      initialized = false;
      skyEnabled = true;
   }

   public void initDesktop() {
      /*desktop = new JMEDesktop("desktop",
            display.getWidth(), display.getHeight()); */
      desktop = new WomDesktop("desktop", input);
      desktop.getLocalTranslation().set( display.getWidth() / 2, display.getHeight() / 2, 0 );
      desktop.updateGeometricState(0, true);
      desktop.updateRenderState();
      if (rootNode != null)
         rootNode.attachChild(desktop);
   }




   public WomDesktop(String name, int w, int h, InputHandler input)
   {
      super(name);
      instance = this;
      autoShowTarget = true;
      windows = 0;
      converter = new ChatConverter();
      desktop = new JMEDesktop("desktop", w, h, input);
      attachChild(desktop);
      desktop.setLightCombineMode(LightState.OFF);
      desktop.getJDesktop().setBackground(new Color(1, 1, 1, 0.0f));
      womCSS = defaultCSS();
      MetalLookAndFeel.setCurrentTheme(new WomTheme());
      try {
         UIManager.setLookAndFeel(new MetalLookAndFeel());
         SwingUtilities.updateComponentTreeUI(desktop.getJDesktop());
      } catch (Exception e) {
         _log.warning(e.toString());
      }
      desktop.setColorBuffer( null );
        desktop.setDefaultColor( new ColorRGBA( 1, 1, 1, 0.5f ) );
        desktop.setRenderQueueMode(Renderer.QUEUE_ORTHO);


The above method works for toggling between mouse look and absolute mouse on the desktop with the system cursor.



Again this is the part where I toggle between the modes. As soon as I call setMouseLook() the picture just jumps on each small mouse move as if I call setMouseCursor() I get two mouse cursors at different moving speeds.



protected void update(float interpolation) {
                newCamLocation = null;
                float hot = 99999;
                ticks++;

                timer.update();

                tpf = timer.getTimePerFrame();

                if (desktop.isFocusOwner()) {
                        // absolute mouse mode
                        input.getMouseLookHandler().setEnabled(false);
                        gui.setHudEnabled(false);
                        //((WomMouseHandler)input.getMouseLookHandler()).setMouseCursor();
                        MouseInput.get().setCursorVisible(true);
                } else       {
                        // mouse look mode
                        input.getMouseLookHandler().setEnabled(true);
                        gui.setHudEnabled(true);
                        MouseInput.get().setCursorVisible(false);
                        //((WomMouseHandler)input.getMouseLookHandler()).setMouseLook();
                        desktop.setFocus("chat");
                }

                Atmosphere.getInstance().update(tpf);
                input.update(tpf);

irrisor said:

You can use MouseLook and AbsoluteMouse. Just call setUsingDelta( false ) on your absolute mouse to make it work with JMEDesktop as well.

That solved the two mouse cursor problem but the bigger one was that mouse look was uncontrollable. I finally found the reason for that. The update function toggled the mouse on each frame instead of just one time on a button click. I cleaned up the source - adding the absolute mouse in the mouselookhandler was a bad idea and I was confused.



Thanks for your time and here is how it looks now:

http://www.world-of-mystery.de/download/screen00030.png