-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
91 lines (72 loc) · 2.82 KB
/
main.cpp
File metadata and controls
91 lines (72 loc) · 2.82 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
83
84
85
86
87
88
89
90
91
#include "include/SceneManager.hpp"
#include "include/simulation/Boid.hpp"
#include "include/simulation/SimulationManager.hpp"
#include "include/ui/UiDataContainer.hpp"
#include "include/ui/UiManager.hpp"
#include "threepp/cameras/PerspectiveCamera.hpp"
#include "threepp/canvas/WindowSize.hpp"
#include "threepp/controls/OrbitControls.hpp"
#include "threepp/core/Clock.hpp"
#include "threepp/geometries/ConeGeometry.hpp"
#include "threepp/materials/MeshStandardMaterial.hpp"
#include "threepp/math/Color.hpp"
#include "threepp/renderers/GLRenderer.hpp"
#include "threepp/scenes/Scene.hpp"
void setupBoidSim(SimulationManager& simMan) {
auto vec = std::vector<std::unique_ptr<BoidConfig>>();
vec.emplace_back(std::make_unique<BoidConfig>());
vec.emplace_back(std::make_unique<BoidConfig>());
simMan.addBoidConfig(std::move(vec[0]));
simMan.addBoidConfig(std::move(vec[1]));
auto configs = simMan.getBoidConfigs();
simMan.createBoids(configs[0], 100);
simMan.createBoids(configs[1], 10);
}
void setupBoidVisuals(const std::vector<BoidConfig*>& configs, SceneManager& sceneMan) {
auto g = threepp::ConeGeometry::create(0.25, 1.0f);
g->rotateX(threepp::math::degToRad(-90));
auto m = threepp::MeshStandardMaterial::create();
m->color.setRGB(1.0f, 1.0f, 0.6f);
sceneMan.addBoidVisualization(*configs[0], g, m);
auto mR = threepp::MeshStandardMaterial::create();
mR->color.setRGB(1.0f, 0.3f, 0.1f);
sceneMan.addBoidVisualization(*configs[1], g, mR);
}
void setupBoids(SimulationManager& simMan, SceneManager& sceneMan) {
setupBoidSim(simMan);
setupBoidVisuals(simMan.getBoidConfigs(), sceneMan);
}
int main() {
//threepp setup
threepp::Canvas canvas("Boids", {{"aa", 4}});
threepp::GLRenderer renderer(canvas.size());
renderer.autoClear = false;
auto camera = threepp::PerspectiveCamera::create(75, canvas.aspect(), 0.1f, 1000);
camera->position.z = 5;
auto scene = threepp::Scene::create();
scene->background = threepp::Color::black;
threepp::OrbitControls controls{*camera, canvas};
canvas.onWindowResize([&](const threepp::WindowSize& size) {
camera->aspect = size.aspect();
camera->updateProjectionMatrix();
renderer.setSize(size);
});
//Setup boid simulation with scene and UI controls
auto simMan = SimulationManager();
auto sceneMan = SceneManager(*scene, simMan);
setupBoids(simMan, sceneMan);
sceneMan.setupDefaultScene();
auto uiData = UiDataContainer(simMan, sceneMan);
UiManager ui(canvas, uiData);
//threepp render and logic loop
threepp::Clock clock;
canvas.animate([&]() {
float dt = clock.getDelta();
simMan.update(dt);
sceneMan.update(dt);
renderer.clear();
renderer.render(*scene, *camera);
ui.render();
});
return 0;
}