Mouse relative position wrong values

Hello ,

I am getting weird mouse relative position with SDL 2.0.3 .
The first mouse motion after the mouse click gives huge values after that
the relative coords are correct is there a workaround or I have to
calculate relative mouse coordinates myself ?
I am testing the code under OSX and IOS . Or if there is a way to ignore
the first event.

This is example code:

int x;
int y;

SDL_Event evt;
while(SDL_PollEvent(&evt))
{
switch(evt.type)
{

    case SDL_MOUSEMOTION:
           x = evt.motion.xrel
           y = evt.motion.yrel
        break;
}

}

First two clicks on the screen.

INFO: x: -22, y: -354
INFO: x: -184, y: 808

Thanks,
Alex

Anyone ?

Heya,

You aren’t using SDL2’s “independent resolution scaling” AKA logical size viewport (SDL_SetLogicalSize & friends) by chance, are you? If so, perhaps it may be possible that it could be interfering with your results? (Pure speculation from me)

You can see how the values are adjusted to account for the feature in SDL_render.c:SDL_RendererEventWatch event handling for SDL_MOUSEMOTION, SDL_MOUSEBUTTONDOWN, SDL_MOUSEBUTTONUP

I am on Mac OS X v10.9.4 and did not appear to exhibit the odd behavior you describe, given your test sample. My testing sample was this file: http://pastebin.com/D7Sr3UJq (built off SDL2 v2.0.3 framework bundle).

Cheers,
Jeffrey Carpenter
<@Jeffrey_Carpenter>On 2014/09/ 21, at 12:13, Alexander Chaliovski wrote:

Hello ,

I am getting weird mouse relative position with SDL 2.0.3 .
The first mouse motion after the mouse click gives huge values after that the relative coords are correct is there a workaround or I have to calculate relative mouse coordinates myself ?
I am testing the code under OSX and IOS . Or if there is a way to ignore the first event.

This is example code:

int x;
int y;

SDL_Event evt;
while(SDL_PollEvent(&evt))
{
switch(evt.type)
{

    case SDL_MOUSEMOTION:
           x = evt.motion.xrel
           y = evt.motion.yrel
        break;
}

}

First two clicks on the screen.

INFO: x: -22, y: -354
INFO: x: -184, y: 808

Thanks,
Alex


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

Thank you for your reply. It happend on IOS . It seems the mouse
SDL_MOUSEMOTION was including the event SDL_MOUSEBUTTONDOWN .
Do we have to check first for SDL_MOUSEBUTTONDOWN and then listen for
SDL_MOUSEMOTION events ?

Thanks,

AlexOn Mon, Sep 22, 2014 at 11:24 PM, Jeffrey Carpenter wrote:

Heya,

You aren’t using SDL2’s “independent resolution scaling” AKA logical size
viewport (SDL_SetLogicalSize & friends) by chance, are you? If so, perhaps
it may be possible that it could be interfering with your results? (Pure
speculation from me)

You can see how the values are adjusted to account for the feature in
SDL_render.c:SDL_RendererEventWatch event handling for SDL_MOUSEMOTION,
SDL_MOUSEBUTTONDOWN, SDL_MOUSEBUTTONUP

I am on Mac OS X v10.9.4 and did not appear to exhibit the odd behavior
you describe, given your test sample. My testing sample was this file:
http://pastebin.com/D7Sr3UJq (built off SDL2 v2.0.3 framework bundle).

Cheers,
Jeffrey Carpenter

On 2014/09/ 21, at 12:13, Alexander Chaliovski <@Alexander_Chaliovski> wrote:

Hello ,

I am getting weird mouse relative position with SDL 2.0.3 .
The first mouse motion after the mouse click gives huge values after
that the relative coords are correct is there a workaround or I have to
calculate relative mouse coordinates myself ?
I am testing the code under OSX and IOS . Or if there is a way to ignore
the first event.

This is example code:

int x;
int y;

SDL_Event evt;
while(SDL_PollEvent(&evt))
{
switch(evt.type)
{

    case SDL_MOUSEMOTION:
           x = evt.motion.xrel
           y = evt.motion.yrel
        break;
}

}

First two clicks on the screen.

INFO: x: -22, y: -354
INFO: x: -184, y: 808

Thanks,
Alex


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