Jump to content
  • Advertisement
Sign in to follow this  
Forkaster

[SDL] Getting and Setting the mouse Cursor

This topic is 3502 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I am fiddling around with SDL 1.2.13 and trying to control the camera look at with the mouse. Using the mouse to look around. If i use window's library i get no probs. But getting the mouse position with SDL_GetMouseState always returns 0 on both coordinates. I also have tried only using the window's GetCursosPos function and SDL_WarpMouse to set the position, but it seems that this one does not work properly as well. Can some one help me? I don't mind losing SDL, but i would like to make the the "look around" with mouse multiplataform and i only know how to do it in windows.

Share this post


Link to post
Share on other sites
Advertisement
I just use a "handle input" type function like so (this is just the 'skeleton' version of the function, without any functionality filled in except for the mouse position handling which you asked about).

I am not sure if you already have an event handling loop in yr SDL app, but it should be only run once per frame. [I assume you already know this; I am just including this for completeness.]

Here is a small snippet with all other event handling not included:

while( SDL_PollEvent( &event ) )
{
if( event.type == SDL_MOUSEMOTION )
{
xMouse = event.motion.x; // (x/y)Mouse variables are member
yMouse = event.motion.y; // variables of the player class
// that tracks mouse movement.
}
}



Here is more of a complete (skeleton) event handling loop to see the overall context:

int Player::handle_input(SDL_Event event)
{
// This function is the event handler function. It takes the user's input and
// sets the appropriate input member variable flags.
// Processing should not be performed here; only flag setting is permitted.

//If a key was pressed
int event_return = 1;

while( SDL_PollEvent( &event ) )
{

if( event.type == SDL_QUIT )
{ //Quit the program
event_return = 0;
}

if( event.type == SDL_KEYDOWN )
{ //Adjust the player coordinates
switch( event.key.keysym.sym )
{
//
}
}

if( event.type == SDL_KEYUP )
{ //Adjust the player coordinates
switch( event.key.keysym.sym )
{
//
}
}


if( event.type == SDL_MOUSEBUTTONDOWN )
{
if ( event.button.button == SDL_BUTTON_WHEELUP )
{
//
}

if ( event.button.button == SDL_BUTTON_WHEELDOWN )
{
//
}

if ( event.button.button == SDL_BUTTON_LEFT )
{
//
}

if ( event.button.button == SDL_BUTTON_MIDDLE )
{
//
}

if ( event.button.button == SDL_BUTTON_RIGHT )
{
//
}

}


if( event.type == SDL_MOUSEBUTTONUP )
{
if ( event.button.button == SDL_BUTTON_LEFT )
{
//
}

if ( event.button.button == SDL_BUTTON_MIDDLE )
{
//
}

if ( event.button.button == SDL_BUTTON_RIGHT )
{
//
}
}

if( event.type == SDL_MOUSEMOTION )
{
xMouse = event.motion.x;
yMouse = event.motion.y;

}

}
return event_return;
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!