Hi, I've noticed something strange and I'm sorry if I overlooked something.
The documentation says
The origin of an object defines the center point for all transformations (position, scale, rotation). The coordinates of this point must be relative to the top-left corner of the object, and ignore all transformations (position, scale, rotation). The default origin of a drawable object is (0, 0).
This is true for sprites. However, when I was trying to rotate a line, I've noticed that shapes use the RenderWindow's 0, 0 point as origin. Is this at all intended behavior? It is not mentioned anywhere I've looked.
For instance, the following code:
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow app(sf::VideoMode(400, 400, 32), "Lines");
sf::Shape line1 = sf::Shape::Line(300.f, 100.f, 350.f, 100.f, 1.f, sf::Color::Blue);
sf::Shape line2 = sf::Shape::Line(300.f, 100.f, 350.f, 100.f, 1.f, sf::Color::White);
line1.SetRotation(10.f);
line2.SetRotation(20.f);
while (app.IsOpened())
{
sf::Event event;
while (app.PollEvent(event)) {}
app.Clear(sf::Color::Black);
app.Draw(line1);
app.Draw(line2);
app.Display();
//if I add these two lines, I can see the shapes orbiting around the top-left corner
line1.Rotate(0.1f);
line2.Rotate(0.1f);
}
return 0;
}
produces this:
To get the desired (and expected) effect, I'd have to do:
sf::Shape line1 = sf::Shape::Line(300.f, 100.f, 350.f, 100.f, 1.f, sf::Color::Blue);
sf::Shape line2 = sf::Shape::Line(300.f, 100.f, 350.f, 100.f, 1.f, sf::Color::White);
line1.SetOrigin(300.f, 100.f);
line1.Move(300.f, 100.f);
line2.SetOrigin(300.f, 100.f);
line2.Move(300.f, 100.f);
line1.SetRotation(10.f);
line2.SetRotation(20.f);
which feels very unnatural.
Am I doing something wrong? Did I miss something? I'd expect some mention of this in the documentation.