[solved] camera rotations with mouse

Hello!

Is anybody know how to perform camera rotations with mouse? Which classes in jogl2 can i use for that?
I try like this:


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 :). any idea? thanks

Do a web search on “rollerball” and/or ken shoemake. (edit: or arcball)

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);
		}
	}


}

[/quote]
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;
dmysensibility == camera rotation around X axis (RX)
dmx
sensibility == camera rotation around Y axis (RY)

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.

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… :-\

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

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.

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.

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

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.