blob: 90fb184d478ff83295eebe7f0b218d130d4b9106 (
plain)
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
|
/*
core/physics.cc
This file is part of the Osirion project and is distributed under
the terms and conditions of the GNU General Public License version 2
*/
#include "model/collisionmesh.h"
#include "core/physics.h"
#include "core/zone.h"
#include "BulletCollision/Gimpact/btGImpactCollisionAlgorithm.h"
namespace core {
btDefaultCollisionConfiguration *Physics::physics_configuration = 0;
btCollisionDispatcher *Physics::physics_dispatcher = 0;
btSequentialImpulseConstraintSolver *Physics::physics_solver = 0;
unsigned long Physics::physics_timestamp = 0;
void Physics::init()
{
con_print << "^BInitializing physics engine..." << std::endl;
model::CollisionModel::init();
physics_configuration = new btDefaultCollisionConfiguration();
physics_dispatcher = new btCollisionDispatcher(physics_configuration);
btGImpactCollisionAlgorithm::registerAlgorithm(physics_dispatcher);
physics_solver = new btSequentialImpulseConstraintSolver;
physics_timestamp = 0;
}
void Physics::done()
{
con_print << "^BShutting down physics engine..." << std::endl;
model::CollisionModel::shutdown();
delete physics_solver;
delete physics_dispatcher;
delete physics_configuration;
physics_configuration = 0;
physics_dispatcher = 0;
physics_solver = 0;
}
void Physics::frame(const unsigned long timestamp)
{
if (!timestamp)
return;
const float seconds = (float) (timestamp - physics_timestamp) / 1000.0f;
for (core::Zone::Registry::iterator it = core::Zone::registry().begin(); it != core::Zone::registry().end(); it++) {
(*it).second->physics()->stepSimulation(seconds);
}
physics_timestamp = timestamp;
}
} // namespace core
|