The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Why do I get so few points(SDL_MOUSEMOTION) when I move fast
NetCraft


Joined: 22 May 2016
Posts: 15
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? Smile
sgrsgsrg


Joined: 06 Sep 2016
Posts: 18
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.
Why do I get so few points(SDL_MOUSEMOTION) when I move fast
MrOzBarry


Joined: 26 Jun 2010
Posts: 620
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:
Quote:
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

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

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


Joined: 12 Feb 2014
Posts: 38
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 wrote:
Quote:
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:
Quote:

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

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org



_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Why do I get so few points(SDL_MOUSEMOTION) when I move fast
Faluk


Joined: 16 Apr 2015
Posts: 17
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:
Quote:
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 wrote:
Quote:
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:
Quote:

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

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org



_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


NetCraft


Joined: 22 May 2016
Posts: 15
Thanks. I'll try to interpolate my points via Bezier curve. Hope it helps Smile
Why do I get so few points(SDL_MOUSEMOTION) when I move fast
Ryan C. Gordon
Guest

On 9/13/16 5:03 PM, Ismael Serrano wrote:
Quote:
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);|

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.


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Why do I get so few points(SDL_MOUSEMOTION) when I move fast
Ryan C. Gordon
Guest

On 9/13/16 11:11 AM, sgrsgsrg wrote:
Quote:
I think it's limited by what windows sends with its API

Specifically:
https://blogs.msdn.microsoft.com/oldnewthing/20031001-00/?p=42343/

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.


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
NetCraft


Joined: 22 May 2016
Posts: 15
I use SDL for Mac/Win/Android operating systems. So I think the solution will be different on those systems?