Camera movement with mouse

Hi
Im trying to make camera rotation movements on y and x axis, on OpenGL, but
I dont know what to do to avoid the limits of the screen…

Here is what Im doing:

SDL_WarpMouse(0,0);
SDL_WM_GrabInput( SDL_GRAB_ON );

//main loop:

lx = mx + lx; ly = my + ly; lz = mz + lz;

``````    gluLookAt( mx,  my,  mz,
lx,  ly,  lz,
0.0,  1.0,  0.0 );
``````

//event loop:

case SDL_MOUSEMOTION :

``````                mm = true;
newx = _event.motion.x; newy = _event.motion.y;
//newx = _event.motion.xrel; newy = _event.motion.yrel;

break;
``````

//event loop finished

if( mm == true ){

``````        //get the difference:
mvelx = newx - oldx;
mvely = newy - oldy;

mvelx = mvelx * 0.001f;
mvely = mvely * 0.001f;

//save current:
oldx = newx;
oldy = newy;

//change it on the angle of rotation:
cangle =  cangle + mvelx;
ly -= mvely;

mm = false;
``````

}

lx = (sin(cangle)); lz = (-cos(cangle)); //rotate the
camera

I tried use the relatives, but it just ‘bonces’ the camera( I dont get what
are those relatives…?)…The code is ok (rotates fine) until it get on the
limit( with is 0 - 640 on x and 0 - 420 on y)…
Can you help me?

Normally in games when you create a camera that is controlled through mouse
you move the mousecursor back to the center of the screen again. Nehe have

In this case after you have taken the event of a mouse move you should
SDL_WarpMouse again.

2009/3/19 Giuliano Pieta > Hi

Im trying to make camera rotation movements on y and x axis, on OpenGL, but
I dont know what to do to avoid the limits of the screen…

Here is what Im doing:

SDL_WarpMouse(0,0);
SDL_WM_GrabInput( SDL_GRAB_ON );

//main loop:

lx = mx + lx; ly = my + ly; lz = mz + lz;

``````    gluLookAt( mx,  my,  mz,
lx,  ly,  lz,
0.0,  1.0,  0.0 );
``````

//event loop:

case SDL_MOUSEMOTION :

``````                mm = true;
newx = _event.motion.x; newy = _event.motion.y;
//newx = _event.motion.xrel; newy = _event.motion.yrel;

break;
``````

//event loop finished

if( mm == true ){

``````        //get the difference:
mvelx = newx - oldx;
mvely = newy - oldy;

mvelx = mvelx * 0.001f;
mvely = mvely * 0.001f;

//save current:
oldx = newx;
oldy = newy;

//change it on the angle of rotation:
cangle =  cangle + mvelx;
ly -= mvely;

mm = false;
``````

}

lx = (sin(cangle)); lz = (-cos(cangle)); //rotate
the camera

I tried use the relatives, but it just ‘bonces’ the camera( I dont get what
are those relatives…?)…The code is ok (rotates fine) until it get on the
limit( with is 0 - 640 on x and 0 - 420 on y)…
Can you help me?

SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

I tried that too, but i didnt realize how i should do that right…If I put
the mouse on the 0,0 after get the coordinates, it never will do
"incremental" stuff…It will just get stucked on the center…

2009/3/20 Tobias Arrskog > Normally in games when you create a camera that is controlled through mouse

you move the mousecursor back to the center of the screen again. Nehe have

In this case after you have taken the event of a mouse move you should
SDL_WarpMouse again.

2009/3/19 Giuliano Pieta <@Giuliano_Pieta>

Hi
Im trying to make camera rotation movements on y and x axis, on OpenGL,
but I dont know what to do to avoid the limits of the screen…

Here is what Im doing:

SDL_WarpMouse(0,0);
SDL_WM_GrabInput( SDL_GRAB_ON );

//main loop:

lx = mx + lx; ly = my + ly; lz = mz + lz;

``````    gluLookAt( mx,  my,  mz,
lx,  ly,  lz,
0.0,  1.0,  0.0 );
``````

//event loop:

case SDL_MOUSEMOTION :

``````                mm = true;
newx = _event.motion.x; newy = _event.motion.y;
//newx = _event.motion.xrel; newy = _event.motion.yrel;

break;
``````

//event loop finished

if( mm == true ){

``````        //get the difference:
mvelx = newx - oldx;
mvely = newy - oldy;

mvelx = mvelx * 0.001f;
mvely = mvely * 0.001f;

//save current:
oldx = newx;
oldy = newy;

//change it on the angle of rotation:
cangle =  cangle + mvelx;
ly -= mvely;

mm = false;
``````

}

lx = (sin(cangle)); lz = (-cos(cangle)); //rotate
the camera

I tried use the relatives, but it just ‘bonces’ the camera( I dont get
what are those relatives…?)…The code is ok (rotates fine) until it get on
the limit( with is 0 - 640 on x and 0 - 420 on y)…
Can you help me?

SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

This is what I do during an mousemotion event.

Sdl.SDL_GetMouseState(out x, out y);
dx = x - centerX;
dy = y - centerY;

float sensativity = 30.0f;
bool invertMouse = false;
camera.rotateX((invertMouse ? 1.0f : -1.0f ) * dy * frameTime *
sensativity);
camera.rotateY(dx * frameTime * sensativity);
Sdl.SDL_WarpMouse((short)centerX, (short)centerY);

2009/3/20 Giuliano Pieta > I tried that too, but i didnt realize how i should do that right…If I put

the mouse on the 0,0 after get the coordinates, it never will do
"incremental" stuff…It will just get stucked on the center…

2009/3/20 Tobias Arrskog <@Tobias_Arrskog>

Normally in games when you create a camera that is controlled through mouse

you move the mousecursor back to the center of the screen again. Nehe have

In this case after you have taken the event of a mouse move you should
SDL_WarpMouse again.

2009/3/19 Giuliano Pieta

Hi
Im trying to make camera rotation movements on y and x axis, on OpenGL,
but I dont know what to do to avoid the limits of the screen…

Here is what Im doing:

SDL_WarpMouse(0,0);
SDL_WM_GrabInput( SDL_GRAB_ON );

//main loop:

lx = mx + lx; ly = my + ly; lz = mz + lz;

``````    gluLookAt( mx,  my,  mz,
lx,  ly,  lz,
0.0,  1.0,  0.0 );
``````

//event loop:

case SDL_MOUSEMOTION :

``````                mm = true;
newx = _event.motion.x; newy = _event.motion.y;
//newx = _event.motion.xrel; newy =
``````

_event.motion.yrel;

``````                break;
``````

//event loop finished

if( mm == true ){

``````        //get the difference:
mvelx = newx - oldx;
mvely = newy - oldy;

mvelx = mvelx * 0.001f;
mvely = mvely * 0.001f;

//save current:
oldx = newx;
oldy = newy;

//change it on the angle of rotation:
cangle =  cangle + mvelx;
ly -= mvely;

mm = false;
``````

}

lx = (sin(cangle)); lz = (-cos(cangle)); //rotate
the camera

I tried use the relatives, but it just ‘bonces’ the camera( I dont get
what are those relatives…?)…The code is ok (rotates fine) until it get on
the limit( with is 0 - 640 on x and 0 - 420 on y)…
Can you help me?

SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

if( mm == true ){//if mouse moved

``````        //center cursor:
SDL_WarpMouse(320,210);

//get the difference:
newx = newx - 320;        newy = newy - 210;//gets how much
``````

moved
mvelx = mvelx + newx; mvely = mvely + newy;//update movement

``````        //makes movement + smooth:
mvelx = mvelx * 0.001f;
mvely = mvely * 0.001f;

//change it on the angle of rotation:
cangle += mvelx;
ly -= mvely;

mm = false;

}
``````

That works, i just wasnt updating the mvelx with the old values, but just
restarting it…
Thanx for the help

2009/3/20 Tobias Arrskog > This is what I do during an mousemotion event.

Sdl.SDL_GetMouseState(out x, out y);
dx = x - centerX;
dy = y - centerY;

float sensativity = 30.0f;
bool invertMouse = false;
camera.rotateX((invertMouse ? 1.0f : -1.0f ) * dy * frameTime *
sensativity);
camera.rotateY(dx * frameTime * sensativity);
Sdl.SDL_WarpMouse((short)centerX, (short)centerY);

2009/3/20 Giuliano Pieta <@Giuliano_Pieta>

I tried that too, but i didnt realize how i should do that right…If I put

the mouse on the 0,0 after get the coordinates, it never will do
"incremental" stuff…It will just get stucked on the center…

2009/3/20 Tobias Arrskog

Normally in games when you create a camera that is controlled through

mouse you move the mousecursor back to the center of the screen again. Nehe

In this case after you have taken the event of a mouse move you should
SDL_WarpMouse again.

2009/3/19 Giuliano Pieta <@Giuliano_Pieta>

Hi
Im trying to make camera rotation movements on y and x axis, on OpenGL,
but I dont know what to do to avoid the limits of the screen…

Here is what Im doing:

SDL_WarpMouse(0,0);
SDL_WM_GrabInput( SDL_GRAB_ON );

//main loop:

lx = mx + lx; ly = my + ly; lz = mz + lz;

``````    gluLookAt( mx,  my,  mz,
lx,  ly,  lz,
0.0,  1.0,  0.0 );
``````

//event loop:

case SDL_MOUSEMOTION :

``````                mm = true;
newx = _event.motion.x; newy = _event.motion.y;
//newx = _event.motion.xrel; newy =
``````

_event.motion.yrel;

``````                break;
``````

//event loop finished

if( mm == true ){

``````        //get the difference:
mvelx = newx - oldx;
mvely = newy - oldy;

mvelx = mvelx * 0.001f;
mvely = mvely * 0.001f;

//save current:
oldx = newx;
oldy = newy;

//change it on the angle of rotation:
cangle =  cangle + mvelx;
ly -= mvely;

mm = false;
``````

}

lx = (sin(cangle)); lz = (-cos(cangle)); //rotate
the camera

I tried use the relatives, but it just ‘bonces’ the camera( I dont get
what are those relatives…?)…The code is ok (rotates fine) until it get on
the limit( with is 0 - 640 on x and 0 - 420 on y)…
Can you help me?

SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org