-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
71 lines (57 loc) · 2.11 KB
/
main.cpp
File metadata and controls
71 lines (57 loc) · 2.11 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
#include <chrono>
#include <iostream>
#include "Simulation.hpp"
#include "PerformanceMonitor.hpp"
#include "Renderer.hpp"
int main() {
// Get gravity input
float gravity;
std::cout << "Enter gravity value (default -9.81): ";
std::string input;
std::getline(std::cin, input);
gravity = input.empty() ? -9.81f : std::stof(input);
// Get initial particle speed
float initialSpeed;
std::cout << "Enter initial particle speed (default 1.0): ";
std::getline(std::cin, input);
initialSpeed = input.empty() ? 1.0f : std::stof(input);
// Get air friction coefficient
float airFriction;
std::cout << "Enter air friction coefficient (0.0-1.0, default 0.47): ";
std::getline(std::cin, input);
airFriction = input.empty() ? 0.47f : std::stof(input);
// Get particle count without arbitrary limits
size_t numParticles;
do {
std::cout << "Enter the number of particles: ";
std::cin >> numParticles;
if (std::cin.fail()) {
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::cout << "Invalid input. Please enter a number.\n";
continue;
}
break;
} while (true);
try {
Simulation sim(numParticles, gravity, initialSpeed, airFriction);
PerformanceMonitor perfMon;
Renderer renderer;
std::cout << "Initializing Particle Simulation...\n";
float speedMultiplier = 1.0f;
while (!renderer.shouldClose()) {
perfMon.beginFrame();
// Speed control with keyboard
if (renderer.isKeyPressed('Q')) speedMultiplier *= 1.1f;
if (renderer.isKeyPressed('E')) speedMultiplier *= 0.9f;
sim.update(1.0f / 60.0f, speedMultiplier);
renderer.render(sim.getParticles());
perfMon.endFrame();
}
perfMon.printMetrics();
} catch (const std::exception& e) {
std::cerr << "Error: " << e.what() << std::endl;
return 1;
}
return 0;
}