-
Notifications
You must be signed in to change notification settings - Fork 8
/
seq-simulator.cpp
59 lines (50 loc) · 1.85 KB
/
seq-simulator.cpp
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
#include "quad-tree.h"
#include "world.h"
#include <algorithm>
#include <iostream>
// TASK 1
// NOTE: You may modify any of the contents of this file, but preserve all
// function types and names. You may add new functions if you believe they will
// be helpful.
const int QuadTreeLeafSize = 8;
class SequentialNBodySimulator : public INBodySimulator {
public:
std::unique_ptr<QuadTreeNode> buildQuadTree(std::vector<Particle> &particles,
Vec2 bmin, Vec2 bmax) {
// TODO: implement a function that builds and returns a quadtree containing
// particles.
return nullptr;
}
virtual std::unique_ptr<AccelerationStructure>
buildAccelerationStructure(std::vector<Particle> &particles) {
// build quad-tree
auto quadTree = std::make_unique<QuadTree>();
// find bounds
Vec2 bmin(1e30f, 1e30f);
Vec2 bmax(-1e30f, -1e30f);
for (auto &p : particles) {
bmin.x = fminf(bmin.x, p.position.x);
bmin.y = fminf(bmin.y, p.position.y);
bmax.x = fmaxf(bmax.x, p.position.x);
bmax.y = fmaxf(bmax.y, p.position.y);
}
quadTree->bmin = bmin;
quadTree->bmax = bmax;
// build nodes
quadTree->root = buildQuadTree(particles, bmin, bmax);
if (!quadTree->checkTree()) {
std::cout << "Your Tree has Error!" << std::endl;
}
return quadTree;
}
virtual void simulateStep(AccelerationStructure *accel,
std::vector<Particle> &particles,
std::vector<Particle> &newParticles,
StepParameters params) override {
// TODO: implement sequential version of quad-tree accelerated n-body
// simulation here, using quadTree as acceleration structure
}
};
std::unique_ptr<INBodySimulator> createSequentialNBodySimulator() {
return std::make_unique<SequentialNBodySimulator>();
}