diff options
Diffstat (limited to 'src/core/physics.cc')
-rw-r--r-- | src/core/physics.cc | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/core/physics.cc b/src/core/physics.cc new file mode 100644 index 0000000..a8577b3 --- /dev/null +++ b/src/core/physics.cc @@ -0,0 +1,54 @@ +/* + 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 "core/physics.h" +#include "core/zone.h" + +namespace core { + +btDefaultCollisionConfiguration *Physics::physics_configuration; +btCollisionDispatcher *Physics::physics_dispatcher; +btSequentialImpulseConstraintSolver *Physics::physics_solver; +unsigned long Physics::physics_timestamp; + +void Physics::init() +{ + con_print << "^BInitializing physics engine..." << std::endl; + + physics_configuration = new btDefaultCollisionConfiguration(); + physics_dispatcher = new btCollisionDispatcher(physics_configuration); + physics_solver = new btSequentialImpulseConstraintSolver; + + physics_timestamp = 0; +} + +void Physics::done() +{ + con_print << "^Bshutting down physics engine..." << std::endl; + 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
\ No newline at end of file |