So I wrote the following lines in a RenderWindow's update loop to test making a sprite always rotate to face the mouse cursor:
sf::Vector2f spritePos = sprite.getPosition();
sf::Vector2f mousePos = window.mapPixelToCoords(sf::Mouse::getPosition());
float angle = atan2(mousePos.y - spritePos.y, mousePos.x - spritePos.x) * 57.296f;
sprite.setRotation(angle);
It was very wonky - the angle was never exactly correct, was always more accurate in the lower-right quadrant than any other, seemed to get more accurate as the mouse got farther from the sprite (but still never particularly accurate). Just generally not behaving the way I expected.
I spent a while tweaking it and tearing my hair out trying to figure out if I just didn't understand the math. Then, on a whim, I decided to try it in fullscreen mode. In fullscreen mode it worked perfectly.
So... is there an issue with mouse accuracy in windowed mode? Is there anything I need to do in my code to make this work in windowed mode, or should I just resign myself to fullscreen mode if I'm going to be doing mouse tracking like this?
Using SFML 2.3 in Windows 7, compiled with Visual Studio 2013, if it matters. Is this a known issue specific to Windows' window system, by any chance? Thanks for any help.