Why do I get so few points(SDL_MOUSEMOTION) when I move fast

My code in mainloop is:

Code:
SDL_Event event;
while ( SDL_PollEvent( &event ) ) {
switch( event.type ) {
case SDL_MOUSEMOTION:
std::ostringstream os;
os << "coords: " << (float)event.motion.x << “x” << (float)event.motion.y << “\n”;
std::cout << os.str().c_str() << std::endl;
break;
}
}

The FPS of “this code” is about 500-700FPS. I move my mouse cursor very fast.
Why do I get so few points(SDL_MOUSEMOTION) when I move my cursor VERY fast from left corner of my window to the right corner (my window’s size is: 900x500). I expected to see at least 50-100 points but I get only 2-3 points.

I don’t understand why does it work like this? I loose many points I don’t know how to catch them. If I move my cursor slowly - it works fine but when it comes to really fast mouse moving from one corner to another all falls apart.

Any suggestions? :slight_smile:

I think it’s limited by what windows sends with its API, maybe it’s locked on the main display frequency? If you want more points you’ll need to interpolate between them. Like when you draw with a painting program, they all use some sort of bezier interpolation to make nice curves, otherwise it would looks like multiple segments linked to each other.

I think most apps interpolate with curves, which isn’t too bad if you have
at least 3 points. I’ve seen this behaviour for years, and I don’t think
it’s an issue with SDL.On Tue, Sep 13, 2016 at 11:11 AM, sgrsgsrg wrote:

I think it’s limited by what windows sends with its API, maybe it’s locked
on the main display frequency? If you want more points you’ll need to
interpolate between them. Like when you draw with a painting program, they
all use some sort of bezier interpolation to make nice curves, otherwise it
would looks like multiple segments linked to each other.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Hi,
Try using relative mouse mode (SDL_SetRelativeMouseMode(SDL_True); ) -
this requests raw mouse events, with no acceleration and at the full
rate your mouse can send them. This is implemented on Windows, and I
think, Linux.

What OS / SDL version / mouse model was this on? The maximum event
rate depends on the mouse.
EricOn Tue, Sep 13, 2016 at 9:20 AM, Alex Barry <alex.barry at gmail.com> wrote:

I think most apps interpolate with curves, which isn’t too bad if you have
at least 3 points. I’ve seen this behaviour for years, and I don’t think
it’s an issue with SDL.

On Tue, Sep 13, 2016 at 11:11 AM, sgrsgsrg wrote:

I think it’s limited by what windows sends with its API, maybe it’s locked
on the main display frequency? If you want more points you’ll need to
interpolate between them. Like when you draw with a painting program, they
all use some sort of bezier interpolation to make nice curves, otherwise it
would looks like multiple segments linked to each other.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Or you can get the current position on the update and compare with the
previous to check if there is any difference.

///--- Store the current information to the previous
m_iPreviousCoordX=m_iCurrentCoordX;
m_iPreviousCoordY=m_iCurrentCoordY;
m_uPreviousMouseState=m_uCurrentMouseState;

///--- Update the current state of the mouse
m_uCurrentMouseState=SDL_GetMouseState(&m_iCurrentCoordX,

&m_iCurrentCoordY);

2016-09-13 22:58 GMT+02:00 Eric Wasylishen :> Hi,

Try using relative mouse mode (SDL_SetRelativeMouseMode(SDL_True); ) -
this requests raw mouse events, with no acceleration and at the full
rate your mouse can send them. This is implemented on Windows, and I
think, Linux.

What OS / SDL version / mouse model was this on? The maximum event
rate depends on the mouse.
Eric

On Tue, Sep 13, 2016 at 9:20 AM, Alex Barry <alex.barry at gmail.com> wrote:

I think most apps interpolate with curves, which isn’t too bad if you
have
at least 3 points. I’ve seen this behaviour for years, and I don’t think
it’s an issue with SDL.

On Tue, Sep 13, 2016 at 11:11 AM, sgrsgsrg wrote:

I think it’s limited by what windows sends with its API, maybe it’s
locked

on the main display frequency? If you want more points you’ll need to
interpolate between them. Like when you draw with a painting program,
they

all use some sort of bezier interpolation to make nice curves,
otherwise it

would looks like multiple segments linked to each other.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Thanks. I’ll try to interpolate my points via Bezier curve. Hope it helps :slight_smile:

To be clear: SDL_GetMouseState() returns the last-known mouse positions,
based on what events the OS has previously sent. It’s more convenient in
some cases than relying on SDL’s event loop, but it’s not any more accurate.

–ryan.On 9/13/16 5:03 PM, Ismael Serrano wrote:

Or you can get the current position on the update and compare with the
previous to check if there is any difference.
| ||///— Update the current state of the mouse|
| ||m_uCurrentMouseState=SDL_GetMouseState(&m_iCurrentCoordX,
&m_iCurrentCoordY);|

Specifically:

If you’re getting really imprecise mouse input, you probably need to
run the SDL event queue more often (is there an SDL_Delay() or something
in your program?), as mouse resolution on Windows is limited to how fast
you check for more mouse events.

(Switching on relative mouse mode in SDL might help, as I assume Win32
RAWINPUT isn’t limited in this way.)

–ryan.On 9/13/16 11:11 AM, sgrsgsrg wrote:

I think it’s limited by what windows sends with its API

I use SDL for Mac/Win/Android operating systems. So I think the solution will be different on those systems?