Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [solved] camera rotations with mouse  (Read 5301 times)
0 Members and 1 Guest are viewing this topic.
Offline dim_9999

Senior Newbie





« Posted 2011-02-05 04: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
« Reply #1 - Posted 2011-02-05 09:26:18 »

Do a web search on "rollerball" and/or ken shoemake.  (edit: or arcball)
Offline DzzD
« Reply #2 - Posted 2011-02-05 11: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! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Roquen
« Reply #3 - Posted 2011-02-05 12: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

Senior Newbie





« Reply #4 - Posted 2011-02-05 13: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

Senior Newbie





« Reply #5 - Posted 2011-02-05 13: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
« Reply #6 - Posted 2011-02-05 14: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

Senior Newbie





« Reply #7 - Posted 2011-02-05 14: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
« Reply #8 - Posted 2011-02-05 15: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

Senior Newbie





« Reply #9 - Posted 2011-02-06 07: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! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Z-Knight

Senior Member


Medals: 1



« Reply #10 - Posted 2011-04-14 22: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

Senior Newbie





« Reply #11 - Posted 2011-04-30 14: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

Senior Member


Medals: 1



« Reply #12 - Posted 2011-05-02 16: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]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Riven (15 views)
2014-07-29 18:09:19

Riven (10 views)
2014-07-29 18:08:52

Dwinin (10 views)
2014-07-29 10:59:34

E.R. Fleming (28 views)
2014-07-29 03:07:13

E.R. Fleming (10 views)
2014-07-29 03:06:25

pw (40 views)
2014-07-24 01:59:36

Riven (39 views)
2014-07-23 21:16:32

Riven (27 views)
2014-07-23 21:07:15

Riven (29 views)
2014-07-23 20:56:16

ctomni231 (59 views)
2014-07-18 06:55:21
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!