#include <msp/game/component.h>
#include <msp/geometry/angle.h>
#include <msp/linal/vector.h>
+#include "setups.h"
-struct RigidBodySetup
+struct RigidBodyData
{
- float mass = 1.0f;
- float moment_of_inertia = 0.5f;
+ 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::Component
+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;
- Msp::LinAl::Vector<float, 2> force;
- float torque = 0.0f;
public:
RigidBody(Msp::Game::Handle<Msp::Game::Entity>, const Setup &);
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 velocity; }
- Msp::Geometry::Angle<float> get_angular_velocity() const { return angular_velocity; }
- const Msp::LinAl::Vector<float, 2> &get_force() const { return force; }
- float get_torque() const { return torque; }
+ 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