-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
83 lines (70 loc) · 2.29 KB
/
main.cpp
File metadata and controls
83 lines (70 loc) · 2.29 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "particle.h"
#include <SFML/Graphics.hpp>
#include <SFML/Graphics/CircleShape.hpp>
#include <SFML/Graphics/Color.hpp>
#include <SFML/System/Time.hpp>
#include <SFML/System/Vector2.hpp>
#include <SFML/Window/Event.hpp>
#include <SFML/Window/Keyboard.hpp>
#include <SFML/Window/Mouse.hpp>
#include <cmath>
#include <cstdint>
#include <cstdlib>
#include <stdio.h>
#include <vector>
int main() {
srand(time(NULL));
sf::RenderWindow window(sf::VideoMode(800, 600), "Particle Simulation Test");
window.setFramerateLimit(60);
printf("Particle Simulation Test\n");
solver simulationSolver;
float radius = 10.0f;
sf::Vector2f spawnPosition = {400.0f, 60.0f};
std::vector<sf::CircleShape> particleShapes;
particleShapes.push_back(newParticle(simulationSolver, spawnPosition, radius, sf::Color::Red));
sf::CircleShape background(bgRadius);
background.setFillColor(sf::Color::Black);
bgPosition = {400.0f, 300.0f};
background.setOrigin(295.0f, 295.0f);
background.setPosition(bgPosition);
sf::Time t;
sf::Clock clock, timer;
int s, val = 255;
while (window.isOpen()) {
sf::Event event;
sf::Mouse mouse;
sf::Vector2f mousePos;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed)
window.close();
if (event.type == sf::Event::MouseButtonPressed) {
// radius = 4.0f + (rand() % 10);
mousePos.x = mouse.getPosition().x - (bgPosition.x / 2 + 50 + radius);
mousePos.y = mouse.getPosition().y - radius;
mousePos -= background.getOrigin();
sf::CircleShape particleShape = newParticle(simulationSolver, mousePos, radius, sf::Color::Red);
}
}
t = timer.getElapsedTime();
s = t.asMilliseconds();
if (s >= 175) {
timer.restart();
radius = 4.0f + (rand() % 10);
particleShapes.push_back(
newParticle(simulationSolver, spawnPosition, radius, sf::Color(val, 123, 123, 255)));
}
float dt = clock.restart().asSeconds();
simulationSolver.update(dt);
window.clear(sf::Color(180, 180, 180, 255));
window.draw(background);
for (const auto &obj : simulationSolver.m_objects) {
sf::CircleShape particleShape(obj.radius);
particleShape.setFillColor(sf::Color::Red);
particleShape.setOrigin(obj.radius, obj.radius);
particleShape.setPosition(obj.currentPosition);
window.draw(particleShape);
}
window.display();
}
return 0;
}