We have 2 overloads of sf::setOrigin:
setOrigin (float x, float y)
setOrigin (const Vector2f& origin)
There is another useful overload for getting origin to the center of the shape as it is quite useful as a lot of transformation has sence about center of the entity. For that it would be useful simple function without parameter. Or it could be through enum but it seems to me that function is used quite a lot and it would be really useful having it directly in the class.
setOrigin()
SFML has several types of entities:
CircleShape - it is easy by the radius
RectangleShape - it is easy by the size
ConvexShape - average of points
Sprite - from rectangle
Text - from its bounds
I think that because it's easy to do, it probably doesn't necessarily need to be in SFML itself. Who knows though?!
For a 'catch all', you can use the bounds for all of them:
template <class T>
void centerOrigin(T& object)
{
const sf::FloatRect bounds{ object.getLocalBounds() };
object.setOrigin({ bounds.left + (bounds.width / 2.f), bounds.top + (bounds.height / 2.f) });
}
That should work for all SFML objects and uses their actual bounds to calculate the centre.
It's also exactly how I did it in Plinth, along with other origin calculations... (https://github.com/Hapaxia/Plinth/blob/master/Plinth/Sfml/Anchor.inl#L68-L73)