#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;
+ 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;
public:
RigidBody(Msp::Game::Handle<Msp::Game::Entity>, const Setup &);
float get_mass() const { return setup.mass; }
+ float get_moment_of_inertia() const { return setup.moment_of_inertia; }
void set_velocity(const Msp::LinAl::Vector<float, 2> &);
- const Msp::LinAl::Vector<float, 2> &get_velocity() const { return velocity; }
+ void set_angular_velocity(Msp::Geometry::Angle<float>);
+ 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