/
Main.cpp
50 lines (39 loc) · 1.2 KB
/
Main.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
#include <Siv3D.hpp>
#include "Mover.hpp";
void Main()
{
Scene::SetBackground(ColorF{ 0.0, 0.0, 0.0 });
const int32 particleMAX = 10;
const int32 width = Scene::Width();
const int32 height = Scene::Height();
const Point windowSize = Point(width, height);
const float coefficientFriction = 0.01;
std::vector<Mover> movers(particleMAX);
for (int32 count = 0; count < particleMAX; count++) {
const Vec2 position = Vec2(0, 0);
const double mass = Random<double>(5.0, 20.0);
Mover mover = Mover(position, mass);
movers.push_back(mover);
}
//std::cout << movers.size() << std::endl;
while (System::Update())
{
for (int32 count = 0; count < movers.size(); count++) {
const double mass = movers[count].mass;
const Vec2 wind = Vec2(0.05, 0.0);
const Vec2 gravity = Vec2(0.0, 0.1 * mass);
Vec2 friction = movers[count].velocity;
friction *= -1;
// ここはnormalizeではない?
// friction.normalize();
friction.normalized();
friction *= coefficientFriction;
movers[count].applyForce(wind);
movers[count].applyForce(gravity);
movers[count].applyForce(friction);
movers[count].update();
movers[count].render();
movers[count].checkEdge(windowSize);
}
}
}