-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
54 lines (44 loc) · 1.41 KB
/
Copy pathmain.cpp
File metadata and controls
54 lines (44 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <cmath>
#include <optional>
#include <iostream>
#include <algorithm>
#include <SFML/Graphics.hpp>
#include "headers/utils.hpp"
#include "headers/intersect.hpp"
#include "headers/path.hpp"
int main() {
sf::RenderWindow window(sf::VideoMode(800, 600), "Knot");
std::vector<sf::VertexArray> path;
std::optional<sf::Vector2f> lastPosition;
sf::VertexArray* previousCross[2] = {nullptr,nullptr};
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed)
window.close();
if (event.type == sf::Event::MouseButtonPressed) {
if (sf::Mouse::isButtonPressed(sf::Mouse::Right)) {
connectEnds(path);
updateIntersections(path,previousCross);
}
if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
resetPath(path,lastPosition,previousCross);
}
if (event.type == sf::Event::MouseMoved) {
if (sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
updatePath(path,lastPosition,(sf::Vector2f)sf::Mouse::getPosition(window));
updateIntersections(path,previousCross);
}
}
if (event.type == sf::Event::KeyPressed) {
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space))
toggleCross(previousCross);
}
}
window.clear(sf::Color::Black);
for (auto& r: path)
window.draw(r);
window.display();
}
return 0;
}