void reset() override { following = nullptr; path.clear(); smoothedPath.clear(); positionInPath = 0; #ifdef _DEBUG debugDraw.clear(); #endif }
int main() { sf::Clock clock; double s = 0; double viewZoom = 1.0f; srand(time(0)); for (u32 i = 0; i < PN; i++) { particule[i]._px = rand() % WINX; particule[i]._py = rand() % WINY; if (INITIAL_SPEED_ACTIVATE) { particule[i]._mx = ((rand() % INITIAL_SPEED) - INITIAL_SPEED / 2) / INITIAL_SPEED_DIV; particule[i]._my = ((rand() % INITIAL_SPEED) - INITIAL_SPEED / 2) / INITIAL_SPEED_DIV; } else { particule[i]._mx = 0; particule[i]._my = 0; } particule[i]._mass = PAR_MASS; particule[i]._color = PCOLOR; } planet.setPosition(sf::Vector2f(WINX/2, WINY/2)); planet.setOrigin(sf::Vector2f(10.0f, 10.0f)); planet.setFillColor(sf::Color::Blue); win.create(sf::VideoMode(WINX, WINY), "ORBITE"); win.setFramerateLimit(MAXFPS); clock.restart(); while (win.isOpen()) { s = clock.restart().asSeconds(); s *= SPEED; sf::View view = win.getDefaultView(); view.zoom(viewZoom); while (win.pollEvent(eve)) { if (eve.type == sf::Event::Closed) win.close(); if (eve.type == sf::Event::KeyPressed) { if (eve.key.code == sf::Keyboard::Add) viewZoom -= 0.25f; else if (eve.key.code == sf::Keyboard::Subtract) viewZoom += 0.25f; else if (eve.key.code == sf::Keyboard::Space) { trace.clear(); for (u32 i = 0; i < PN; i++) { particule[i]._px = rand() % WINX; particule[i]._py = rand() % WINY; if (INITIAL_SPEED_ACTIVATE) { particule[i]._mx = ((rand() % INITIAL_SPEED) - INITIAL_SPEED / 2) / INITIAL_SPEED_DIV; particule[i]._my = ((rand() % INITIAL_SPEED) - INITIAL_SPEED / 2) / INITIAL_SPEED_DIV; } else { particule[i]._mx = 0; particule[i]._my = 0; } particule[i]._mass = PAR_MASS; particule[i]._color = PCOLOR; } } } } planet.setPosition((sf::Vector2f)sf::Mouse::getPosition(win)); for (u32 i = 0; i < PN; i++) { particule[i].updateToPosition(planet.getPosition(), PL_MASS, s); part[i].position = sf::Vector2f(particule[i]._px, particule[i]._py); part[i].color = particule[i]._color; if (ACTIVATE_ORBIT_TRACE) { sf::Vertex cpy = part[i]; trace.append(cpy); } } win.setView(view); win.clear(sf::Color::Black); win.draw(planet); win.draw(part); win.draw(trace); win.display(); } return (0); }