Author Topic: Using the mouse to move the camera  (Read 8217 times)

Albareth

  • Guest
Using the mouse to move the camera
« on: December 28, 2003, 03:24:23 pm »
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...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Using the mouse to move the camera
« Reply #1 on: December 29, 2003, 03:45:10 pm »
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

  • Guest
Using the mouse to move the camera
« Reply #2 on: December 29, 2003, 03:56:30 pm »
Thanks....  I think that should help, although a mouse implementation would be useful....

Offline acorn98

  • byte
  • *
  • Posts: 46
    • View Profile
Using the mouse to move the camera
« Reply #3 on: January 09, 2004, 02:36:54 am »
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

  • Guest
Re: Using the mouse to move the camera
« Reply #4 on: October 15, 2004, 08:06:51 pm »
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Using the mouse to move the camera
« Reply #5 on: October 16, 2004, 01:00:15 am »
Quote
IF 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:

Offline Mike Nelson

  • byte
  • *
  • Posts: 6
    • View Profile
Using the mouse to move the camera
« Reply #6 on: October 17, 2004, 01:41:06 am »
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

Offline Mike Nelson

  • byte
  • *
  • Posts: 6
    • View Profile
Moving the Mouse
« Reply #7 on: October 20, 2004, 07:19:33 am »
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. . . .

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Moving the Mouse
« Reply #8 on: October 28, 2004, 08:17:49 pm »
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).

Offline Melssj5

  • double
  • *****
  • Posts: 724
    • View Profile
Using the mouse to move the camera
« Reply #9 on: December 06, 2004, 09:55:20 pm »
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