Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  Print  
  [solved] camera rotations with mouse  (Read 2063 times)
0 Members and 2 Guests are viewing this topic.
Offline dim_9999

JGO n00b
*

Posts: 15



« on: 2011-02-04 22:10:52 »

Hello!

Is anybody know how to perform camera rotations with mouse? Which classes in jogl2 can i use for that?
I try like this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
canvas.addMouseMotionListener(new MouseMotionListener() {
         @Override
         public void mouseMoved(MouseEvent e) {
            // TODO Auto-generated method stub
           
             xLookAt = e.getPoint().getX()/10.0f;
             yLookAt = e.getPoint().getY()/10.0f;
             zLookAt = 100;

         }


But this is baaad Smiley. any idea? thanks

Love is a lonely laughter resonant in the middle of endless moaning of hell
Offline Roquen

JGO Strike Force
***

Posts: 827
Medals: 25



« Reply #1 on: 2011-02-05 03:26:18 »

Do a web search on "rollerball" and/or ken shoemake.  (edit: or arcball)
Offline DzzD

JGO Kernel
*****

Posts: 2134
Medals: 16



« Reply #2 on: 2011-02-05 05:41:56 »

not  realy JOGL related but this one give me good result :

Quote
public class FPSMouseControler implements MouseMotionListener
   {
      int mx=0;
      int my=0;
      int screenX;
      int screenY;
      int screenXDiv2;
      int screenYDiv2;
      public int dmx=0;
      public int dmy=0;
      Canvas c;
      
      Robot robot;

      public FPSMouseControler() throws Exception
      {
            robot = new Robot();
            Toolkit t = Toolkit.getDefaultToolkit();
            screenX = t.getScreenSize().width;
            screenY = t.getScreenSize().height;
            screenXDiv2=screenX>>1;
            screenYDiv2=screenY>>1;
      }
      
      public void setCanvas(Canvas c)
      {
         if(this.c!=null)
            this.removeCanvas(this.c);
            
         this.c=c;
         c.addMouseMotionListener(this);   
         
            
      }
      
      public void removeCanvas(Canvas c)
      {
         c.removeMouseMotionListener(this);   
         this.c=null;
         
      }
      
      
      public void mouseDragged(MouseEvent e)
      {
         this.mouseMoved(e);
      }
        
      public void mouseMoved(MouseEvent e)  
      {
         mx=e.getXOnScreen();
         my=e.getYOnScreen();
         if(mx!=screenXDiv2 || my!=screenYDiv2)
         {
            if(mx!=screenXDiv2)
            {
               dmx+=mx-screenXDiv2;
            }
            if(my!=screenYDiv2)
            {
               dmy+=my-screenYDiv2;   
            }
            robot.mouseMove(screenXDiv2, screenYDiv2);
         }
      }


   }

attach it once to your canvas (jogl canvas in your case) :

fpsMouseController = new FPSMouseController();
fpsMouseController.setCanvas(mycanvas);


then later when you need to know camera rotation :

sensibility = 0.01;
dmy*sensibility  == camera rotation around X axis (RX)
dmx*sensibility  == camera rotation around Y axis (RY)

Games published by our own members! Go get 'em!
Offline Roquen

JGO Strike Force
***

Posts: 827
Medals: 25



« Reply #3 on: 2011-02-05 06:14:56 »

Humm.  I guess before we give can you some suggestions, you need to describe what you want.  I'm giving you a pointer for 3rd person, while DzzD is for 1st.
Offline dim_9999

JGO n00b
*

Posts: 15



« Reply #4 on: 2011-02-05 07:42:10 »

not  realy JOGL related but this one give me good result :


Thanks for answer, i have tried your stuff, but when i trying to capture the screen by my mouse, something push out my mouse... And i can't realize why is the Robot here?...
And when i tried without robot, the dmx and dmy coords always incremented irrespectively at what direction i turn my mouse... Undecided


Love is a lonely laughter resonant in the middle of endless moaning of hell
Offline dim_9999

JGO n00b
*

Posts: 15



« Reply #5 on: 2011-02-05 07:49:00 »

Humm.  I guess before we give can you some suggestions, you need to describe what you want.  I'm giving you a pointer for 3rd person, while DzzD is for 1st.

Well, i need to set gluLookAt() method by mouse... the camera position in my case is static...

Love is a lonely laughter resonant in the middle of endless moaning of hell
Offline DzzD

JGO Kernel
*****

Posts: 2134
Medals: 16



« Reply #6 on: 2011-02-05 08:08:30 »

... And i can't realize why is the Robot here?...

you probably forgot to import java.awt.Robot

Robot is a standard Java classes (it wont work without, it is used to place back the mouse at the center of the screen after each mouse displacement)

Offline dim_9999

JGO n00b
*

Posts: 15



« Reply #7 on: 2011-02-05 08:44:03 »

... And i can't realize why is the Robot here?...

you probably forgot to import java.awt.Robot

Robot is a standard Java classes (it wont work without, it is used to place back the mouse at the center of the screen after each mouse displacement)

robot is fine(was imported...). problem is when i trying to capture the screen by my mouse, something push out mouse...(i can't capture the screen...)

Love is a lonely laughter resonant in the middle of endless moaning of hell
Offline DzzD

JGO Kernel
*****

Posts: 2134
Medals: 16



« Reply #8 on: 2011-02-05 09:20:24 »

... And i can't realize why is the Robot here?...

you probably forgot to import java.awt.Robot

Robot is a standard Java classes (it wont work without, it is used to place back the mouse at the center of the screen after each mouse displacement)

robot is fine(was imported...). problem is when i trying to capture the screen by my mouse, something push out mouse...(i can't capture the screen...)

ha yes ! sorry I misunderstood....

you cannot put the mouse over your game window ?

this version is very basic maybe you have to addapt it to fit your need , this one always put the mouse at the center of the screen

Offline dim_9999

JGO n00b
*

Posts: 15



« Reply #9 on: 2011-02-06 01:38:58 »

... And i can't realize why is the Robot here?...

you probably forgot to import java.awt.Robot

Robot is a standard Java classes (it wont work without, it is used to place back the mouse at the center of the screen after each mouse displacement)

robot is fine(was imported...). problem is when i trying to capture the screen by my mouse, something push out mouse...(i can't capture the screen...)

ha yes ! sorry I misunderstood....

you cannot put the mouse over your game window ?

this version is very basic maybe you have to addapt it to fit your need , this one always put the mouse at the center of the screen

Thanks a lot man! This is what i exactly want.

Love is a lonely laughter resonant in the middle of endless moaning of hell
Games published by our own members! Go get 'em!
Offline Z-Knight

Full Member
**

Posts: 234



« Reply #10 on: 2011-04-14 16:37:49 »

This may or may not be useful...I had written some code for doing First Person Shooter controls.

Here is a http://www.zaczek.com/jogl/TestFPS_Camera.jnlp.

Here is access to source code: http://www.zaczek.com/jogl/TestFPS_Camera/TestFPS_Camera.zip

Here are the controls...you can hold down the mouse to rotate (left mouse button) while using left/right/up/down to translate simultaneously.

Left mouse down to rotate view
middle mouse button to zoom
right mouse button to pan
up/down/left/right arrows (also ASWD keys) to move into/around the scene
page up/down to pan up/down
1,2,3 keys to orient you along X,Y,Z axes

Basically the controls are much like you see in the fly through/observation mode of most first person shooter games.

'O' key switches from "Standard mode" to "Orbiting Mode"

'F' key switches from "FPS Emulation" to "Free Fly Through" modes...the FPS Emulation is like running around in a First Person shooter where you can only look up/down/left/right, while Free FLy Through mode lets you rotate in any direction.

Standard mode is like a FPS mode. Orbiting mode you will orbit the object in the center.

Offline dim_9999

JGO n00b
*

Posts: 15



« Reply #11 on: 2011-04-30 08:07:35 »

Hi! thanx for the source. I will learn it. but as i can see this stuff is jogl 1.1 related...

Love is a lonely laughter resonant in the middle of endless moaning of hell
Offline Z-Knight

Full Member
**

Posts: 234



« Reply #12 on: 2011-05-02 10:19:24 »

It was written when JOGL 1.1 was out and hence using JOGL 1.1 calls, but it is basically OpenGL code - the important stuff is the matrix calculations, etc that make up the rotations.
It is not tied to JOGL version. I'm pretty sure you can just use it in any JOGL version by simply changing JOGL 1.1 calls to JOGL 2.0, etc calls - though I suspect most calls should be exactly the same.
Pages: [1]
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.142 seconds with 21 queries.