#include <SFML/Graphics.hpp>
#include <thread>
#include <chrono>
#include <cmath>
#include <iostream>
using namespace std::chrono_literals;
int main() {
sf::RenderWindow App(sf::VideoMode(800, 600), "SFML rect rotation");
App.setFramerateLimit(60);
float angle(1.f);
sf::RectangleShape t({51, 51});
sf::Vector2f origin = {
t.getSize().x/2,
t.getSize().y/2
};
t.setPosition(200 + origin.x, 200 + origin.y);
t.setOrigin(origin);
t.setFillColor(sf::Color::Green);
double anglel_all = 0;
while (App.isOpen()) {
sf::Event Event;
while (App.pollEvent(Event))
if (Event.type == sf::Event::Closed)
App.close();
App.clear();
for(size_t i = 0; i <= 800; i += 50) {
sf::VertexArray A(sf::Lines, 2);
A[0] = sf::Vertex({float(i+0.5), 0+0.5f}, sf::Color::Red);
A[1] = sf::Vertex({float(i+0.5), 600 }, sf::Color::Blue);
App.draw(A);
}
for(size_t j = 0; j <= 600; j += 50) {
sf::VertexArray B(sf::Lines, 2);
B[0] = sf::Vertex({0.5f, float(j+0.5)}, sf::Color::Red);
B[1] = sf::Vertex({800 , float(j+0.5)}, sf::Color::Green);
App.draw(B);
}
anglel_all += angle;
t.rotate(angle);
App.draw(t);
// angle += 0.01f;
App.display();
bool is_int = std::fabs(anglel_all - static_cast<int>(anglel_all)) < 0.1;
bool is_90 = static_cast<int>(anglel_all) % 90 == 0;
if(is_int && is_90) {
std::cout << "Cath" << std::endl;
std::this_thread::sleep_for(1s);
}
}
}