Basic Questions MouseHandler

Hi,

i am new to Jmonkey and still learning.



Question 1:

How can i have a mouse similar to a rts game?

i already saw http://www.jmonkeyengine.com/wiki/doku.php/strategichandler, but that is too much for me now.



all i want is a mouse on the screen, that can scroll if it is on the side of the window.



i already got an absolute mosue that is present on the screen.

and a simplegame as a main class.



// Create a new mouse. Restrict its movements to the display screen.
am = new AbsoluteMouse("The Mouse", display.getWidth(), display
      .getHeight());



and i can shut down rotation of the FPS by adding this line



      ((FirstPersonHandler) input).getMouseLookHandler().setEnabled(false);



what is missing is some code to add an inputhandler that will move the cam if it is on the corner .. thx for help in advance


Ok …

i will answer that to myself:



I implemented my own MouseLook, MyMouseLookHandler,FirstPersonInputHandler



That is really missing in the JME … and it is not much work, but complicated for beginners.



Another Question:



// Move the mouse to the middle of the screen to start with

am.setLocalTranslation(new Vector3f(display.getWidth() / 2, display.getHeight() / 2, 0));



If i move my mouse … it will just get back to position (0,0) … how can i permanently change that position?

I saw this post and wanted to do something similar.  This is my first time using JME and doing any real 3D  development, so excuse the code crudeness.  I am sure there are some better ways to implement this, but this works as something really basic.  It allows you to navigate similar to an RTS, edge of the screen moves in that direction, the mouse wheel zooms in and out.



I just implemented a MouseInputAction and added it to a regular InputHandler:



public class RTSMouseLook extends MouseInputAction {
    private Camera camera;
    private Vector3f upVector;
    private Vector2f bottomLeftCorner;
    private Vector2f topRightCorner;

    public RTSMouseLook(Mouse mouse, Camera camera, float speed,
                        Vector2f bottomLeftCorner, Vector2f topRightCorner) {
        this(mouse, camera, speed, bottomLeftCorner, topRightCorner, null);
    }

    public RTSMouseLook(Mouse mouse, Camera camera, float speed,
                        Vector2f bottomLeftCorner, Vector2f topRightCorner, Vector3f upVector) {
        setMouse(mouse);
        setSpeed(speed);
        this.camera = camera;
        this.upVector = upVector;
        this.bottomLeftCorner = bottomLeftCorner;
        this.topRightCorner = topRightCorner;
    }

    @Override
    public void performAction(InputActionEvent event) {
        Vector3f mouseHotSpot = mouse.getHotSpotPosition();

        if(mouseHotSpot.getX() == bottomLeftCorner.getX()) {
            // move left
            camera.getLocation().addLocal(camera.getLeft().mult(speed * event.getTime()));
            camera.update();
        }
        else if(mouseHotSpot.getX() == topRightCorner.getX()) {
            // move right
            camera.getLocation().subtractLocal(camera.getLeft().mult(speed * event.getTime()));
            camera.update();
        }

        if(mouseHotSpot.getY() == bottomLeftCorner.getY()) {
            // move backward
            if(upVector != null) {
                Vector3f backVector = upVector.cross(camera.getLeft());
                camera.getLocation().addLocal(backVector.mult(speed * event.getTime()));
                camera.update();
            } else {
                camera.getLocation().subtractLocal(camera.getUp().mult(speed * event.getTime()));
                camera.update();
            }
        }
        else if(mouseHotSpot.getY() == topRightCorner.getY()) {
            // move forward
            if(upVector != null) {
                Vector3f backVector = upVector.cross(camera.getLeft());
                camera.getLocation().subtractLocal(backVector.mult(speed * event.getTime()));
                camera.update();
            } else {
                camera.getLocation().addLocal(camera.getDirection().mult(speed * event.getTime()));
                camera.update();
            }
        }

        if(MouseInput.get().getWheelDelta() > 0) {
            // zoom in
            camera.getLocation().addLocal(camera.getDirection().mult(
                    MouseInput.get().getWheelDelta() * speed * event.getTime()));
            camera.update();
        }
        else if(MouseInput.get().getWheelDelta() < 0) {
            // zoom out
            camera.getLocation().subtractLocal(camera.getDirection().mult(
                    -MouseInput.get().getWheelDelta() * speed * event.getTime()));
            camera.update();
        }
    }
}



Next I would like to change to select objects in the scene and move them, that should be interesting... ;)
evilangelist said:

[...]
Next I would like to change to select objects in the scene and move them, that should be interesting... ;)


If you want to move selected objects to a location selected by a mousepick, have a look at this thread.
http://www.jmonkeyengine.com/forum/index.php?topic=11911.msg88899#msg88899
Got the same problem recently :)

P.S.: How do I get the 2D Vectors for bottomLeftCorner and topRightCorner? Are those the Coordinates in 3D Space or the absolute Coordinate of the display?

greetings
Edregol
If you want to move selected objects to a location selected by a mousepick, have a look at this thread.
http://www.jmonkeyengine.com/forum/index.php?topic=11911.msg88899#msg88899
Got the same problem recently


Thx for that, I just got the object selection and object highlighting on the terrain working, so now I need that info.

P.S.: How do I get the 2D Vectors for bottomLeftCorner and topRightCorner? Are those the Coordinates in 3D Space or the absolute Coordinate of the display?


Those params are to set the 2D absolute screen coordinates that determine when camera is moved.  Usually this is just the screen resolution extents (i.e. for a screen resolution of 1024x768: bottomLeftCorner=(0,0) topRightCorner=(1023,767)).

regards
Those params are to set the 2D absolute screen coordinates that determine when camera is moved.  Usually this is just the screen resolution extents (i.e. for a screen resolution of 1024x768: bottomLeftCorner=(0,0) topRightCorner=(1023,767)).


Thanks for that. I was thinking a bit too complex at this time.^^