If someone needs it, here's my workaround to make drawables being flippable. I did it months ago.. I should have kept copies of the matrices, but it was just a quick workaround to test some stuff.
With that I was able to flip shapes, text, and my own drawable classes, like drawable trees.
#ifndef INVERSIBLE_DRAWABLE_HPP
#define INVERSIBLE_DRAWABLE_HPP
#include <SFML/Graphics.hpp>
namespace gm2{
// Note: T inherits from sf::Drawable
template<class T>
class InversibleDrawable: public T{
public:
// default constructor
InversibleDrawable():
T(), myFlipX(false), myFlipY(false)
{
// Nothing to do
}
void flipX(bool flipX){
myFlipX = flipX;
}
void flipY(bool flipY){
myFlipY = flipY;
}
//TODO:
// sf::Vector2f TransformToLocal(const sf::Vector2f& point) const;
// sf::Vector2f TransformToGlobal(const sf::Vector2f& point) const;
private:
// render method
void Render(sf::RenderTarget& target, sf::Renderer& renderer) const{
if (myFlipX || myFlipY){
sf::Matrix3 tmp;
float rot = T::GetRotation();
sf::Vector2f origin = T::GetOrigin();
// Revert origin and rotation
tmp.Transformation( origin, sf::Vector2f(0,0), rot, sf::Vector2f(1,1));
tmp = tmp.GetInverse();
renderer.ApplyModelView(tmp);
// Apply flip
tmp.Transformation( sf::Vector2f(0,0), sf::Vector2f(0,0), 0, sf::Vector2f(myFlipX?-1:1,myFlipY?-1:1));
renderer.ApplyModelView(tmp);
// Apply origin and rotation on the f
tmp.Transformation( origin, sf::Vector2f(0,0), rot, sf::Vector2f(1,1));
renderer.ApplyModelView(tmp);
}
T::Render(target,renderer);
}
private:
// our flip flags
bool myFlipX, myFlipY;
};
typedef InversibleDrawable<sf::Sprite> InversibleSprite;
typedef InversibleDrawable<sf::Shape> InversibleShape;
typedef InversibleDrawable<sf::Text> InversibleText;
} // namespace gm2
#endif // INVERSIBLE_DRAWABLE_HPP