]> git.tdb.fi Git - libs/game.git/blob - examples/bassteroids/source/rigidbody.h
Use the setup generator to create setup structs
[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 #include "setups.h"
8
9 struct RigidBodyData
10 {
11         Msp::LinAl::Vector<float, 2> velocity;
12         Msp::Geometry::Angle<float> angular_velocity;
13         Msp::LinAl::Vector<float, 2> force;
14         float torque = 0.0f;
15 };
16
17 class RigidBody: public Msp::Game::BufferedComponent<RigidBodyData>
18 {
19 public:
20         using Setup = RigidBodySetup;
21
22 private:
23         const Setup &setup;
24
25 public:
26         RigidBody(Msp::Game::Handle<Msp::Game::Entity>, const Setup &);
27
28         float get_mass() const { return setup.mass; }
29         float get_moment_of_inertia() const { return setup.moment_of_inertia; }
30         void set_velocity(const Msp::LinAl::Vector<float, 2> &);
31         void set_angular_velocity(Msp::Geometry::Angle<float>);
32         void add_force(const Msp::LinAl::Vector<float, 2> &);
33         void add_force(const Msp::LinAl::Vector<float, 2> &, const Msp::LinAl::Vector<float, 2> &);
34         void add_torque(float);
35         void clear_forces();
36         const Msp::LinAl::Vector<float, 2> &get_velocity() const { return read().velocity; }
37         Msp::Geometry::Angle<float> get_angular_velocity() const { return read().angular_velocity; }
38         const Msp::LinAl::Vector<float, 2> &get_force() const { return read().force; }
39         float get_torque() const { return read().torque; }
40 };
41
42 #endif