mouse coordinates on edge of screen

Started by
4 comments, last by Khaos Dragon 19 years, 7 months ago
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! :)
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.
There are 10 kinds of people,those who understand binaryand those who not.
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.

Steven Bradley .:Personal Journal:. .:WEBPLATES:. .:CGP Beginners Group:. "Time is our most precious resource yet it is the resource we most often waste." ~ Dr. R.M. Powell
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.
There are 10 kinds of people,those who understand binaryand those who not.
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.
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.

This topic is closed to new replies.

Advertisement