-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsimulator.cpp
More file actions
48 lines (45 loc) · 1.13 KB
/
simulator.cpp
File metadata and controls
48 lines (45 loc) · 1.13 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
#include "simulator.h"
void simulator::init (renderer * r, ui * u)
{
rend = r;
UI = u;
grav = vec2(0,1);
}
void simulator::process()
{
energy = 0;
for (it = bodies.begin(); it < bodies.end(); ++it)
{
(*it)->coll = false;
(*it)->col_edge = 0;
(*it)->addimpulse((*it)->centre_g, grav, (*it)->mass*10);
}
for (it = bodies.begin(); it < bodies.end(); ++it)
{
(*it)->ishighlited = false;
for (it2 = bodies.begin(); it2 < bodies.end(); ++it2)
if (it != it2)
(*it)->check_coll(*it2);
}
for (it = bodies.begin(); it < bodies.end(); ++it)
{
(*it)->process();
energy += (*it)->vel.length()*(*it)->vel.length() * (*it)->mass;
energy += (*it)->ang_vel*(*it)->ang_vel * (*it)->I;
}
UI->body_at_cursor = BodyAtPos(UI->mouse_pos);
}
pbody* simulator::BodyAtPos(vec2 p)
{
for (bap = bodies.rbegin(); bap < bodies.rend(); ++bap)
{
if (p.x < ((*bap)->bbox.left) || p.x > ((*bap)->bbox.right) || p.y < ((*bap)->bbox.top) || p.y > ((*bap)->bbox.bottom))
continue;
if (pit((*bap)->g_countour[0], (*bap)->g_countour[1], (*bap)->g_countour[2], p))
{
(*bap)->ishighlited = true;
return (*bap);
}
}
return NULL;
}