Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: sf::Mouse::getPosition(window) returning weird values on OSX  (Read 3165 times)

0 Members and 2 Guests are viewing this topic.

tanis

  • Newbie
  • *
  • Posts: 11
    • View Profile
sf::Mouse::getPosition(window) returning weird values on OSX
« 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!

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: sf::Mouse::getPosition(window) returning weird values on OSX
« Reply #1 on: November 23, 2015, 11:09:21 am »
What's your camera's view?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: sf::Mouse::getPosition(window) returning weird values on OSX
« Reply #2 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. :)
SFML / OS X developer

tanis

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: sf::Mouse::getPosition(window) returning weird values on OSX
« Reply #3 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.

tanis

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: sf::Mouse::getPosition(window) returning weird values on OSX
« Reply #4 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!

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: sf::Mouse::getPosition(window) returning weird values on OSX
« Reply #5 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.
SFML / OS X developer