Sign in to follow this  
graveyard filla

how to use relative mouse coordinates ?

Recommended Posts

hi, ive been working on my map editor lately (2D w / C++, OpenGL and SDL). im using SDL for the mouse / all input. anyway, i wanted to add a feature where i could put a scroll bar on the edge of the map, you know, like the kind you have in your web browser -----------------------------> one of those scroll bars you can drag, and the map will scroll with it. so i can quickly scroll through the map by just dragging the bar. anyway, i have the scroll bars set up now, to move with the screen, i just have to allow the user to click and drag the bar...im pretty sure i need to use relative mouse coordinates for this, but i dont understand how it works. i know i can retrieve the relative mouse coordinates via SDL_GetRelativeMouseState(). this function receives 2 int's which it fills with data (x and y). well, once i have this x and y, which represent the relative position of the mouse, now what? how do i tell if the user is dragging up or down or left or right? thanks for any help!!!

Share this post


Link to post
Share on other sites
Jannes    160
I dont know SDL. But you use relative coordinates like this:
Your ints x,y will get filled with the mousemovement from your last position. Just scroll your map by x,y pixels (or adjust to your needs by multiplying with 1.2f for example for faster scrolling, 0.8f slower scrolling). If x is negative it scrolls to the left (positive to the right). If y is negative scroll up (positive down). Assuming the ScreenCoordinateSystem is defined from 0,0 top left corner of the window/screen. Though I think if you are using a scrollbar u wont need relative Mousecoordinates. You will need to retrieve the value of the scrollbars and scroll the map by those (this will be absolute positions).

Share this post


Link to post
Share on other sites
thanks...

but, so, uhh well... so relative position means how much the mouse has changed? IE, when i get the relative mouse positions, they will be something like 300 for x if i moved my mouse 300 to the right since the last frame? or -20 for Y if i moved the mouse 20 pixels up since the last frame? so basically, it just gets the coordites from 2 frames and subtracts them? thanks again!

Share this post


Link to post
Share on other sites
Jannes    160
Quote:
Original post by graveyard filla
thanks...

but, so, uhh well... so relative position means how much the mouse has changed? IE, when i get the relative mouse positions, they will be something like 300 for x if i moved my mouse 300 to the right since the last frame? or -20 for Y if i moved the mouse 20 pixels up since the last frame? so basically, it just gets the coordites from 2 frames and subtracts them? thanks again!


Yep, right.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this