Sign in to follow this  

mouse coordinates on edge of screen

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

This topic is 4844 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.

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