-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.cpp
72 lines (49 loc) · 1.61 KB
/
test.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
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "OctTree.h"
#include "Vec3.h"
#include "NBody.h"
#include <random>
#include <fstream>
#include <chrono>
int main(int argc, char** argv) {
default_random_engine rndJesus(42);
uniform_real_distribution<float> klaus(-100, 100);
OctNode octtree(0, 14 , Vec3f(-100, -100, -100), Vec3f(100, 100, 100));
int num_bods = 10000;
vector<Nbody*> bodys;
for (int i = 0; i < num_bods; i++) {
bodys.push_back(new Nbody(Vec3f(klaus(rndJesus), klaus(rndJesus), klaus(rndJesus)), Vec3f(), 1));
}
cout << "Created particles!" << endl;
auto start = chrono::high_resolution_clock::now();
for (int round = 0; round < 60; round++) {
octtree.clear();
for (int i = 0; i < num_bods; i++) {
octtree.add(bodys[i]);
}
octtree.updateTree();
int num_colls = 0;
vector<int> collisons(num_bods, -1);
vector<Vec3f> acc(num_bods, Vec3f(0,0,0));
for (int i = 0; i < num_bods; i++) {
acc[i] = Vec3f(0, 0, 0);
num_colls += octtree.updateParticle(i, &bodys, &acc, &collisons, 1.f);
acc[i] *= 1;
}
for (int i = 0; i < num_bods; i++) {
bodys[i]->velocity += acc[i];
bodys[i]->position += bodys[i]->velocity * 1;
if (abs(bodys[i]->position.x) > 200 || abs(bodys[i]->position.y) > 200 || abs(bodys[i]->position.z) > 200) {
bodys[i]->velocity -= 0.01f * bodys[i]->position;
}
}
cout << "Done" << endl;
}
auto stop = chrono::high_resolution_clock::now();
auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start);
cout << duration.count()/60 << endl;
//std::ofstream file;
//file.open("./treewrite.xml");
//octtree.write(&file, 0);
//file.close();
//octtree.print();
}