]> git.tdb.fi Git - libs/game.git/blobdiff - examples/bassteroids/source/physics.h
Emit events for colliding physical entities
[libs/game.git] / examples / bassteroids / source / physics.h
index 3d9d7081e7f540e7c7edebcd7f71220fc2ee8d22..fcf4b0dce534396434b5d6667a654f9aeb73e502 100644 (file)
@@ -2,23 +2,29 @@
 #define PHYSICS_H_
 
 #include <msp/game/eventobserver.h>
+#include <msp/game/eventsource.h>
 #include <msp/game/events.h>
 #include <msp/game/handle.h>
 #include <msp/game/system.h>
 #include <msp/geometry/angle.h>
 #include <msp/linal/vector.h>
+#include "events.h"
 
 class PhysicalEntity;
 
 class Physics: public Msp::Game::System
 {
+public:
+       using EventSource = Msp::Game::EventSource<Events::Collision>;
+
 private:
        struct SimulatedEntity
        {
                Msp::Game::Handle<PhysicalEntity> entity;
                float inverse_mass = 1.0f;
-               float moment_of_inertia = 1.0f;
+               float inverse_momi = 1.0f;
                Msp::LinAl::Vector<float, 2> external_force;
+               float external_torque = 0.0f;
 
                Msp::LinAl::Vector<float, 2> position;
                Msp::Geometry::Angle<float> rotation;
@@ -38,6 +44,7 @@ private:
                Msp::LinAl::Vector<float, 2> normal;
        };
 
+       EventSource event_source;
        Msp::Game::EventObserver observer;
        std::vector<SimulatedEntity> entities;
        unsigned fixture_count = 0;