]> git.tdb.fi Git - libs/game.git/blob - examples/bassteroids/source/rigidbody.h
Add rotation to physics simulation
[libs/game.git] / examples / bassteroids / source / rigidbody.h
1 #ifndef RIGIDBODY_H_
2 #define RIGIDBODY_H_
3
4 #include <msp/game/component.h>
5 #include <msp/geometry/angle.h>
6 #include <msp/linal/vector.h>
7
8 struct RigidBodySetup
9 {
10         float mass = 1.0f;
11         float moment_of_inertia = 0.5f;
12 };
13
14 class RigidBody: public Msp::Game::Component
15 {
16 public:
17         using Setup = RigidBodySetup;
18
19 private:
20         const Setup &setup;
21         Msp::LinAl::Vector<float, 2> velocity;
22         Msp::Geometry::Angle<float> angular_velocity;
23
24 public:
25         RigidBody(Msp::Game::Handle<Msp::Game::Entity>, const Setup &);
26
27         float get_mass() const { return setup.mass; }
28         float get_moment_of_inertia() const { return setup.moment_of_inertia; }
29         void set_velocity(const Msp::LinAl::Vector<float, 2> &);
30         void set_angular_velocity(Msp::Geometry::Angle<float>);
31         const Msp::LinAl::Vector<float, 2> &get_velocity() const { return velocity; }
32         Msp::Geometry::Angle<float> get_angular_velocity() const { return angular_velocity; }
33 };
34
35 #endif