Jump to content
  • Advertisement
Sign in to follow this  
Kenny77

SDL Co-ords

This topic is 3701 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

I noticed when debugging my game in SDL that the screen coordinates when getting the mouse position seem to be positive in both directions, starting from the center of the screen (a cartesian plane, but only positive). Does this have any effect if I'm comparing screen positions for surfaces and mouse positions? Because I'm having some problems trying to get menu buttons to react properly.

Share this post


Link to post
Share on other sites
Advertisement
I noticed this also, to fix it I think I did mouseY = GetWindowHeight() - mouseY; or something. Now, however, for all my drawing code in orthomode to the screen, I use SDL's coords by:
glScalef(1, -1, 1); //makes the y axis go down
glTranslatef(0, (float)-GetWindowHeight(), 0); //makes (0, 0) orgin located at the top left

Share this post


Link to post
Share on other sites
Obviously the gl* stuff only applies if you're using OpenGL for rendering. Normally, the screen coordinates should have the origin at one of the left-hand corners (I forget which one in SDL) and everything on screen should be positive. If the mouse is reporting something different as 'screen coordinates', then I'm not sure what's going wrong. Could you post the code you use to read the mouse?

Share this post


Link to post
Share on other sites
The current event gets passed from the game engine to the current state's HandleEvents function.


void MenuState::HandleEvents(GameEngine* game, SDL_Event event)
{
if (event.type == SDL_MOUSEBUTTONDOWN)
{
if (event.button.button == SDL_BUTTON_LEFT)
{
mouseX = event.button.x;
mouseY = event.button.y;

for(buttonIter = buttonList.begin(); buttonIter != buttonList.end(); ++buttonIter)
{
compareRect = (*buttonIter)->GetPosition();

if ((mouseX > compareRect.x) && (mouseX < compareRect.w + compareRect.x)
&& (mouseY > compareRect.y) && (mouseY < compareRect.h + compareRect.y))
{
(*buttonIter)->OnClick();
}
}
}
}
}

Share this post


Link to post
Share on other sites
SDL uses the upper left corner as the origin, with coordinates increasing towards the bottom and right. Just like a regular cartesian plane, but upside down, and only the first quadrant. Negative coordinates would have to be above and/or to the left of the window. I thought every API did it like that...

Share this post


Link to post
Share on other sites
Quote:
Original post by Portmanteau
What type is mouseX and mouse Y? Also try

*** Source Snippet Removed ***

just for kicks.


Thanks! That got it working. The only problem I'm having now is if I click the mouse button and quickly bring it over the button's image (or surface), it acts as if I clicked on it. Is there some sort of quirkiness involved with this?

Share this post


Link to post
Share on other sites
I think the idea was to use that code to verify the values you're being returned, not to use instead of your original code. Since the GetMouseState stuff works differently, it is quite likely to appear 'quirky' if you don't coordinate it properly with the click events.

You need to show some data, so it becomes clear what is going wrong. What values do you get for the mouse position if you click in each of the corners of the screen?

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!