-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathengine.cpp
More file actions
79 lines (64 loc) · 2.02 KB
/
engine.cpp
File metadata and controls
79 lines (64 loc) · 2.02 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
//
// engine.cpp
// MSIM495
//
#include "engine.h"
namespace Physics {
ParticleWorld::ParticleWorld(
unsigned max_contacts,
unsigned iterations
) : resolver(iterations),
max_contacts(max_contacts)
{
contacts = new ParticleContact[max_contacts];
calculate_iterations = (iterations == 0);
}
ParticleWorld::~ParticleWorld() {
delete [] contacts;
}
unsigned ParticleWorld::generate_contacts() {
unsigned limit = max_contacts;
ParticleContact * next_contact = contacts;
ContactGenerators::iterator g = contact_generators.begin();
for (; g != contact_generators.end(); ++g) {
unsigned used = (*g)->add_contact(next_contact, limit);
limit -= used;
next_contact += used;
if (limit <= 0) break;
}
return max_contacts - limit;
}
void ParticleWorld::integrate(real duration) {
Particles::iterator p = particles->begin();
for (; p != particles->end(); ++p) {
(*p)->integrate(duration);
}
}
void ParticleWorld::run_physics(real duration){
registry.update_forces(duration);
integrate(duration);
unsigned used_contacts = generate_contacts();
if (used_contacts) {
if (calculate_iterations) resolver.set_iterations(used_contacts * 2);
resolver.resolve_contacts(contacts, used_contacts, duration);
}
}
// World //
///////////
void World::start_frame() {
RigidBodies::iterator b = bodies.begin();
for (; b != bodies.end(); ++b) {
b->clear_accumulator();
b->calculate_derived_data();
}
}
void World::integrate(real duration) {
RigidBodies::iterator b = bodies.begin();
for (; b != bodies.end(); ++b) {
b->intergrate(duration);
}
}
void World::run_physics(real duration) {
integrate(duration);
}
}