Jump to content
  • Advertisement
Sign in to follow this  
Khaos Dragon

mouse coordinates on edge of screen

This topic is 5154 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 am using SDL for mouse input, but I am not sure if this is an SDL problem or a limitation of input devices... I am implementing a Max Payne like camera system, such that whenever the mouse moves left, the camera rotates left, and vice versa for right, up, and down. The way I do this is to store the old x and y coordinates of the mouse from the last frame and rotate by the differences between those and new x and y coordinates. However, this is not sufficient for when the mouse is at the edge of the screen. For example, if the user's mouse cursor is currently on the left edge of the screen, it will have an x coord of 0. If he moves his mouse left, he will still have an x coord of 0, and no leftward rotation will occur. If anybody has any suggestions, it would be greatly appreciated. Thanks! :)

Share this post


Link to post
Share on other sites
Advertisement
Reset the cursor to a defined position (the center of
the screen for example).


Pseudo:
{
CursorPos=GetCursorPos();

Movement=CursorPos-CenterPos;

CursorPos=CenterPos;
}

Using the center of the screen maximizes the amount
the mouse can be moved in all direction during an update-cycle.

Share this post


Link to post
Share on other sites
I haven't played Max Payne but you might try having a single variable that covers 360 degrees. If your mouse location is left of center subtract and if it is right of center increase. It could be set up to move faster the further from center it is if you wanted variable speeds. Just a thought.

Share this post


Link to post
Share on other sites
In SDL, if you grab and hide (look in the docs) the mouse pointer, it'll automaticly stay in the center of the screen.
Instead of using the x/y coords, you can now use the relx/rely (or xrel,yrel... don't remember) which tell you how far the movement is.

Share this post


Link to post
Share on other sites
Quote:
Original post by Martin Foerster
I guess his intention is to move his crosshair or what ever he has, according to the relative position of the mouse, not the absolute one.


Exactly, anyways I found a function called SDL_WarpMouse which allows me to position the mouse cursor. It also registers a mouse motion event, but I easily got over that by limiting rotation to changes less than half the screen width or height.

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!