Sign in to follow this  

Custom Mouse Pointer

This topic is 4245 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'm implementing a custom drawn mouse pointer. The current implementation renders a sprite with the mouse pointer texture and sets the sprite position to the mouse input XY states (using DiorectInput). However when I try to move the mouse very quickly, the pointer does not responds, just jittering. I figured it could be the locked frame rate of the sprite rendering and mouse input. But I think it's something else has to do with mouse input values. How is that implemented in games?

Share this post


Link to post
Share on other sites
It's immediate get state mode.

The values are correct, and the cursor moves fine when the mouse movement speed is reasonable. but when playing with it very quickly, the cursor jitter, does not move as supposed to be, but it's still witihn some values.

Share this post


Link to post
Share on other sites
Heya,

Are you in fullscreen or windowed mode? There's this thing about absolute and relative coordinates.

By default, DI coordinates will tell you how far the mouse has moved since the last update...not its current screen position.

Also you need to make sure your'e capping coordinates.

This is what I use at the moment, maybe the code will help you:


// In fullscreen mode, we use DirectInput
if ( fullscreen )
{
// Increment absolute positions
mouse_absolute_x += mouse_state.lX;
mouse_absolute_y += mouse_state.lY;
}

// In windowed mode, we use the win32 GetCursorPos()
else
{
POINT cursor;
GetCursorPos( &cursor );
ScreenToClient( Window.GetWindowHandle(), &cursor );
mouse_absolute_x = cursor.x;
mouse_absolute_y = cursor.y;
}

// Clamp absolute x position within window
if ( mouse_absolute_x < 0 ) mouse_absolute_x = 0;
else if ( mouse_absolute_x > Window.GetWindowWidth() )
mouse_absolute_x = Window.GetWindowWidth();

// Clamp absolute y position within window
if ( mouse_absolute_y < 0 ) mouse_absolute_y = 0;
else if ( mouse_absolute_y > Window.GetWindowHeight() )
mouse_absolute_y = Window.GetWindowHeight();



- Pure

Share this post


Link to post
Share on other sites
Thanks mate. But I already tried both the relative (converted to absolute) and the abosulte mouse data to set the cursor pos. That worked pretty normal, but when I move it sooo fast the cursor does not seem respond to fast movement, sticking within an area. I think it's the frame rate locking, or maybe the response of the mouse device, should be some way to work around ...

Share this post


Link to post
Share on other sites
DirectInput has nothing to do with frame rate locking. What may be happening is you're scaling your input units down. Normally, that doesn't matter, but when you have a low value, it gets turned into zero.

For instance, if you usually get 100 units in one tick at 10FPS, and you translate that into 20 pixels, then you divide it by 5 to get your pixel distance to move the cursor by.
If you then jump to 100 FPS, you'd get 10 units in one tick. You divide by 5, and get 2, which is also correct.
Then you jump up to 500 FPS. You get 2 units in one tick. You divide by 5, and get 0 due to the integer truncation.

If that is the case, you could either keep a running total in units returned by DirectInput, and then only scale it when you render your cursor, or keep the cursor position around as a float.

Share this post


Link to post
Share on other sites
It's not that. The main loop frame reads immediate mouse position once and renders the mouse cursor.

what if I need bufferd mouse input instead?

Share this post


Link to post
Share on other sites

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