I am having trouble rotating a triangle. The triangle I am using is a
sf::VertexArray
.
Basically, what I want to do is rotate my triangle around a fixed vertex like the image below.
I did some Googling and found this formula
x' = x * cos(t) - y * sin(t)
y' = x * sin(t) + y * cos(t)
I have tried implementing it like this, but I have had no luck.
Here is the implementation:
sf::Vector2f PointA(350.0f, 350.0f);
sf::Vector2f PointB(250.0f, 340.0f);
sf::Vector2f PointC(250.0f, 360.0f);
triangle[0].position = PointA;
triangle[1].position = PointB;
triangle[2].position = PointC;
triangle[0].color = sf::Color::Blue;
triangle[1].color = sf::Color::Blue;
triangle[2].color = sf::Color::Blue;
while loop
PointA = sf::Vector2f(object.getPosition().x, object.getPosition().y);
PointB = sf::Vector2f(object.getPosition().x - 100.0f, object.getPosition().y - 10.0f);
PointC = sf::Vector2f(object.getPosition().x - 100.0f, object.getPosition().y + 10.0f);
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
{
PointB = sf::Vector2f(PointB.x * cos(10) - PointB.y * sin(10), PointB.x * sin(10) + PointB.y * cos(10));
PointC = sf::Vector2f(PointC.x * cos(10) - PointC.y * sin(10), PointC.x * sin(10) + PointC.y * cos(10));
}
triangle[0].position = PointA;
triangle[1].position = PointB;
triangle[2].position = PointC;
triangle[0].color = sf::Color(0, 0, 255, 20);
triangle[1].color = sf::Color::Blue;
triangle[2].color = sf::Color::Blue;
How would any of you go about rotating the triangle of VertexArray? I have tried making the triangle into a SFML entity, but it rotates the whole triangle relative to the world origin. I want it to rotate around a fixed point, or vertex.