Custom Mouse Pointer

Started by
5 comments, last by quaker 17 years, 11 months ago
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?
Advertisement
Are you using buffered or immediate data? Have you tried logging the values from DirectInput to see if the values are about right?
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.
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 DirectInputif ( 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 windowif ( 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 windowif ( mouse_absolute_y < 0 ) mouse_absolute_y = 0;else if ( mouse_absolute_y > Window.GetWindowHeight() )	mouse_absolute_y = Window.GetWindowHeight();


- Pure
Framerate is LIFE.
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 ...
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.
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?

This topic is closed to new replies.

Advertisement