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
Mouse relative position wrong values
Alexander Chaliovski
Guest

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
Mouse relative position wrong values
Alexander Chaliovski
Guest

Anyone ?
Mouse relative position wrong values
Jeffrey Carpenter
Guest

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 wrote:

Quote:
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

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

_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Mouse relative position wrong values
Alexander Chaliovski
Guest

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,

Alex




On Mon, Sep 22, 2014 at 11:24 PM, Jeffrey Carpenter wrote:
Quote:
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 wrote:

Quote:
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


Quote:
_______________________________________________
SDL mailing list

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

_______________________________________________
SDL mailing list

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