]> git.tdb.fi Git - libs/game.git/blob - source/game/transform.h
Add some useful constructors for TransformValues
[libs/game.git] / source / game / transform.h
1 #ifndef MSP_GAME_TRANSFORM_H_
2 #define MSP_GAME_TRANSFORM_H_
3
4 #include <msp/geometry/quaternion.h>
5 #include <msp/linal/matrix.h>
6 #include <msp/linal/vector.h>
7 #include "component.h"
8
9 namespace Msp::Game {
10
11 struct TransformValues
12 {
13         LinAl::Vector<float, 3> position;
14         Geometry::Quaternion<float> rotation = Geometry::Quaternion<float>::one();
15         LinAl::Vector<float, 3> scale = { 1.0f, 1.0f, 1.0f };
16
17         TransformValues() = default;
18         TransformValues(const LinAl::Vector<float, 3> &p): position(p) { }
19         TransformValues(const LinAl::Vector<float, 3> &p, const Geometry::Quaternion<float> &r,
20                 const LinAl::Vector<float, 3> &s = LinAl::Vector<float, 3>(1.0f, 1.0f, 1.0f)):
21                 position(p), rotation(r), scale(s)
22         { }
23 };
24
25 class Transform: public Component
26 {
27 private:
28         TransformValues values;
29         LinAl::Matrix<float, 4, 4> local_matrix;
30         LinAl::Matrix<float, 4, 4> world_matrix;
31
32 public:
33         Transform(Handle<Entity>);
34
35         void set_values(const TransformValues &);
36         void set_position(const LinAl::Vector<float, 3> &);
37         void set_rotation(const Geometry::Quaternion<float> &);
38         void set_scale(const LinAl::Vector<float, 3> &);
39         const TransformValues &get_values() const { return values; }
40         const LinAl::Vector<float, 3> &get_position() const { return values.position; }
41         const Geometry::Quaternion<float> &get_rotation() const { return values.rotation; }
42         const LinAl::Vector<float, 3> &get_scale() const { return values.scale; }
43         const LinAl::Matrix<float, 4, 4> &get_world_matrix() const { return world_matrix; }
44
45         void update_world_matrix(const Transform *);
46 };
47
48 } // namespace Msp::Game
49
50 #endif