SFML community forums

Help => Window => Topic started by: tanis on November 23, 2015, 11:01:52 am

Title: sf::Mouse::getPosition(window) returning weird values on OSX
Post by: tanis on November 23, 2015, 11:01:52 am
I'm trying to understand what's going on with the mouse position on OSX.

I have the following function:

    Vector2 InputManager::getMousePosition(Camera *camera)
    {
        sf::Vector2i pos = sf::Mouse::getPosition(*window);
        sf::Vector2f worldPos = window->mapPixelToCoords(pos, camera->view);
        return Vector2(worldPos.x, worldPos.y);
    }
 

The value of "pos", when I click near the top left position is (-428, 554) and I can't figure out what those values mean.
The window is positioned in the middle of the screen and the size is 320, 240.

I have a similar function for touches that I use with iOS and it works perfectly instead:

    Vector2 InputManager::getTouchPosition(unsigned int finger, Camera *camera)
    {
        sf::Vector2i pos = sf::Touch::getPosition(finger, *window);
        sf::Vector2f worldPos = window->mapPixelToCoords(pos, camera->view);
        return Vector2(worldPos.x, worldPos.y);
    }

Is that a known bug? (Using SFML 2.3.2)
Thanks!
Title: Re: sf::Mouse::getPosition(window) returning weird values on OSX
Post by: eXpl0it3r on November 23, 2015, 11:09:21 am
What's your camera's view?
Title: Re: sf::Mouse::getPosition(window) returning weird values on OSX
Post by: Hiura on November 23, 2015, 12:05:36 pm
There might be a bug in SFML; I was working on removing deprecated functions from SFML codebase this weekend and noticed something weird too. When I implemented it it worked fine but since then some function got deprecated and I think Apple broke something with the pixel unit conversion in recent OS versions.

Now, if you could provided a sscce that'd be great. :)
Title: Re: sf::Mouse::getPosition(window) returning weird values on OSX
Post by: tanis on November 23, 2015, 12:08:02 pm
What's your camera's view?

The view is set with the same size as the window and with a viewport rect of (0, 0, 1, 1) and its center is in (160, 120) (the center of the window).

I'm not even looking at the calculated "worldPos" because the calculated "pos" is already wrong so the translation to world coordinates makes even less sense.
Title: Re: sf::Mouse::getPosition(window) returning weird values on OSX
Post by: tanis on November 24, 2015, 02:07:40 pm
Any news on this issue? If you need a test case I can send you a zip of my framework. It's not yet released in the wild but it surely is quicker than writing a new test case from scratch. In case please send me your email addresses. Cheers!
Title: Re: sf::Mouse::getPosition(window) returning weird values on OSX
Post by: Hiura on November 24, 2015, 03:07:54 pm
Now, if you could provided a sscce that'd be great. :)

Please, just something minimal that reproduces it.