www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: Albareth on December 28, 2003, 03:24:23 pm

Title: Using the mouse to move the camera
Post by: Albareth 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...
Title: Re: Using the mouse to move the camera
Post by: EgonOlsen 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).
Title: Using the mouse to move the camera
Post by: Albareth on December 29, 2003, 03:56:30 pm
Thanks....  I think that should help, although a mouse implementation would be useful....
Title: Using the mouse to move the camera
Post by: acorn98 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;
  }
Title: Re: Using the mouse to move the camera
Post by: Anonymous 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.
Title: Re: Using the mouse to move the camera
Post by: EgonOlsen 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:
Title: Using the mouse to move the camera
Post by: Mike Nelson 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
Title: Moving the Mouse
Post by: Mike Nelson 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. . . .
Title: Re: Moving the Mouse
Post by: EgonOlsen 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).
Title: Using the mouse to move the camera
Post by: Melssj5 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.