Hello.
Its simple as it sounds, rotating a point around point to simulate clock.
But i got: the point that is supposed to rotate goes away from the point that it is supposed to rotate around and i don't know where i made the mistake.
sf::Vector2f is just a vector of two points, x and y.
Also main for sfml 2.0 for example.
void Rotate(sf::Vector2f & p, double angle, sf::Vector2f r)
{
double pi = 3.14159;
float s = sin(angle);
float c = cos(angle);
r.x -= p.x;
r.y -= p.y;
p.x += r.x * c - r.y * s;
p.y += r.x * s + r.y * c;
}
int main()
{
sf::RenderWindow win;
sf::VideoMode vidMod(800, 600, 32);
win.create(vidMod, "hello", sf::Style::Default);
win.setFramerateLimit(60);
sf::VertexArray vaL;
vaL.setPrimitiveType(sf::Lines);
vaL.append(sf::Vertex(sf::Vector2f(400, 300)));
vaL.append(sf::Vertex(sf::Vector2f(600, 300)));
double angle = 90;
bool done = false;
while (done == false)
{
win.clear();
sf::Event event;
while (win.pollEvent(event))
{
switch (event.type)
{
case sf::Event::Closed:
done = true;
break;
default:
break;
}
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::R))
Rotate(vaL[1].position, angle, vaL[0].position);
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space))
{//Reset data to old
vaL[0] = (sf::Vertex(sf::Vector2f(400, 300)));
vaL[1] = (sf::Vertex(sf::Vector2f(600, 300)));
}
win.draw(vaL);
win.display();
}
return 0;
};