Using the mouse to move the camera

Started by Albareth, December 28, 2003, 03:24:23 PM

Previous topic - Next topic

Albareth

Hey Egon!

Another Q...  How would you use the mouse to rotate the camera, like if the user holds down the right mouse button and moves the mouse, the camera will rotate; if the user holds down both mouse buttons, the camera zooms; if the user moves the cursor to the sides of the screen, the camera will pan?  Any help would be appreciated...

EgonOlsen

Quote from: "Albareth"Hey Egon!

Another Q...  How would you use the mouse to rotate the camera, like if the user holds down the right mouse button and moves the mouse, the camera will rotate; if the user holds down both mouse buttons, the camera zooms; if the user moves the cursor to the sides of the screen, the camera will pan?  Any help would be appreciated...
You should be able to do this by using the rotate- and move- methods for the camera and apply an angle (or offset) to the current position/direction depending on the delta the mouse has moved in the direction in question. In the good old DOS days, i repositioned the mouse pointer in the middle of the screen after getting its position, so that the mouse couldn't move "out of the screen". Don't know if this is possible or even required to be done in Java...i never implemented that kind of camera movement in Java (just because i was to lazy and the keyboard did the job for the things i was doing).

Albareth

Thanks....  I think that should help, although a mouse implementation would be useful....

acorn98

Don't know if this is still an issue, but I've got some mouse-controlled camera code here which works well. you'll need to define all the variables as int:


 public boolean mouseDown(Event e, int x, int y){
     lastx=x;
     lasty=y;
     return true;
 }
 
 public boolean mouseDrag(Event e, int x, int y){
 
        //look left/right with mouse
        camera.rotateAxis(camera.getBack().getYAxis(), (x-lastx)*TURN_SPEED);
        playerDirection.rotateY((x-lastx)*TURN_SPEED);
 
        //look up/down with mouse
         camera.rotateX(-(y-lasty)*TURN_SPEED);
       
   
     lastx=x;
     lasty=y;
     return true;
 }

Anonymous

Quote from: "EgonOlsen"... i repositioned the mouse pointer in the middle of the screen after getting its position, so that the mouse couldn't move "out of the screen". Don't know if this is possible or even required to be done in Java...i never implemented that kind of camera movement in Java ....

IF this is still an issue try using the java.awt.Robot class you can move the mouse pointer, and simulate user input.

EgonOlsen

QuoteIF this is still an issue try using the java.awt.Robot class you can move the mouse pointer, and simulate user input.
Neat idea...i remember that i once wrote a small test that moved the mouse and clicked left and right randomly...my desktop looked really crazy after running it for some time.. :wink:

Mike Nelson

yeah you can do some interesting things with it. i think it was originally designed for automated testing.. i think it would be cool make a J Virtual Network Control program with network commands issued to the local Robot object. . . but thats a whole nother topic

Mike

Mike Nelson

I just realized that would only really work in fullscreen mode.  otherwise if the user moved the Applet/Application the coordinates for the center would be off.. that could screw things up. . . .

EgonOlsen

Quote from: "Mike Nelson"I just realized that would only really work in fullscreen mode.  otherwise if the user moved the Applet/Application the coordinates for the center would be off.. that could screw things up. . . .
That's no problem at all. You can easily determine where the frame is located on the desktop and adjust your coordinates accordingly. I did that in the latest Paradroid 3D alpha and it works fine (at least on Windows XP and Linux..haven't tried others yet).

Melssj5

mouse events is what you need to control the camera through the mouse, you have to use the functions to move the camera, but controled by the mouse, you need a Listener and get coordenates of the cursor on the screen. I Guess!!!.
If the event recieves (java.awt.event.MouseEvent evt) like parameter you can get the position of the cursor on the screen in pixeles by getX () and getY (), both returns an int value.
Nada por ahora