]> git.tdb.fi Git - libs/game.git/blobdiff - examples/bassteroids/source/rigidbody.h
Convert components to buffered where appropriate
[libs/game.git] / examples / bassteroids / source / rigidbody.h
index 6225500237c79f69eb0367994ca4f363cd585c48..b75d034ab98e03b42a4beb81cb08d21532d1f4b4 100644 (file)
@@ -11,15 +11,21 @@ struct RigidBodySetup
        float moment_of_inertia = 0.5f;
 };
 
-class RigidBody: public Msp::Game::Component
+struct RigidBodyData
+{
+       Msp::LinAl::Vector<float, 2> velocity;
+       Msp::Geometry::Angle<float> angular_velocity;
+       Msp::LinAl::Vector<float, 2> force;
+       float torque = 0.0f;
+};
+
+class RigidBody: public Msp::Game::BufferedComponent<RigidBodyData>
 {
 public:
        using Setup = RigidBodySetup;
 
 private:
        const Setup &setup;
-       Msp::LinAl::Vector<float, 2> velocity;
-       Msp::Geometry::Angle<float> angular_velocity;
 
 public:
        RigidBody(Msp::Game::Handle<Msp::Game::Entity>, const Setup &);
@@ -28,8 +34,14 @@ public:
        float get_moment_of_inertia() const { return setup.moment_of_inertia; }
        void set_velocity(const Msp::LinAl::Vector<float, 2> &);
        void set_angular_velocity(Msp::Geometry::Angle<float>);
-       const Msp::LinAl::Vector<float, 2> &get_velocity() const { return velocity; }
-       Msp::Geometry::Angle<float> get_angular_velocity() const { return angular_velocity; }
+       void add_force(const Msp::LinAl::Vector<float, 2> &);
+       void add_force(const Msp::LinAl::Vector<float, 2> &, const Msp::LinAl::Vector<float, 2> &);
+       void add_torque(float);
+       void clear_forces();
+       const Msp::LinAl::Vector<float, 2> &get_velocity() const { return read().velocity; }
+       Msp::Geometry::Angle<float> get_angular_velocity() const { return read().angular_velocity; }
+       const Msp::LinAl::Vector<float, 2> &get_force() const { return read().force; }
+       float get_torque() const { return read().torque; }
 };
 
 #endif