]> git.tdb.fi Git - libs/game.git/blob - source/game/transform.h
603076024adbdd27c2aa659cd5c805c320fa0d51
[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
18 class Transform: public Component
19 {
20 private:
21         TransformValues values;
22         LinAl::Matrix<float, 4, 4> local_matrix;
23         LinAl::Matrix<float, 4, 4> world_matrix;
24
25 public:
26         Transform(Handle<Entity>);
27
28         void set_values(const TransformValues &);
29         void set_position(const LinAl::Vector<float, 3> &);
30         void set_rotation(const Geometry::Quaternion<float> &);
31         void set_scale(const LinAl::Vector<float, 3> &);
32         const TransformValues &get_values() const { return values; }
33         const LinAl::Vector<float, 3> &get_position() const { return values.position; }
34         const Geometry::Quaternion<float> &get_rotation() const { return values.rotation; }
35         const LinAl::Vector<float, 3> &get_scale() const { return values.scale; }
36         const LinAl::Matrix<float, 4, 4> &get_world_matrix() const { return world_matrix; }
37
38         void update_world_matrix(const Transform *);
39 };
40
41 } // namespace Msp::Game
42
43 #endif