Don't just case the mouse pixel position vector2
i to a vector2
f. You should
map the pixel position to the view co-ordinates system:
window.mapPixelToCoords(sf::Mouse::getPosition(window));
See:
http://www.sfml-dev.org/tutorials/2.4/graphics-view.php#coordinates-conversionsBounding rectangles are
always axis-aligned. That is, they cannot be rotated.
Of course, rectangle shapes can. You can "untransform" a rectangle using its inverse transform (or just use its local bounds instead of its global bounds). You can also apply the same inverse transform to the mouse position to see if it is inside the rectangle when converted to the rectangle shape's local co-ordinates.
Something like:
const sf::Vector2f mappedMousePosition = window.mapPixelToCoords(sf::Mouse::getPosition(window));
const sf::Vector2f transformedMousePosition = rectangle.getInverseTransform.transformPoint(mappedMousePosition);
if (rectangle.getLocalBounds.contains(transformedMousePosition))
mouseIsInsideRectange = true;
Notice the use of
local bounds, not global bounds.
I may have missed off the use of the
view's inverse transform...