]> git.tdb.fi Git - libs/gl.git/blob - source/animation/transform.h
Use default member initializers for simple types
[libs/gl.git] / source / animation / transform.h
1 #ifndef MSP_GL_TRANSFORM_H_
2 #define MSP_GL_TRANSFORM_H_
3
4 #include <msp/datafile/objectloader.h>
5 #include "matrix.h"
6
7 namespace Msp {
8 namespace GL {
9
10 /**
11 Stores a coordinate space transform as individual components.  Primarily
12 intended for loading data from external sources.  At runtime transforms
13 should generally be stored as matrices.
14 */
15 class Transform
16 {
17 public:
18         class Loader: public DataFile::ObjectLoader<Transform>
19         {
20         public:
21                 Loader(Transform &);
22
23         private:
24                 void position_x(float);
25                 void position_y(float);
26                 void position_z(float);
27                 void position(float, float, float);
28                 void euler_x(float);
29                 void euler_y(float);
30                 void euler_z(float);
31                 void euler(float, float, float);
32                 void rotation(float, float, float, float);
33                 void scale_x(float);
34                 void scale_y(float);
35                 void scale_z(float);
36                 void scale_uniform(float);
37                 void scale(float, float, float);
38         };
39
40         enum ComponentMask
41         {
42                 NONE = 0,
43                 POSITION_X = 1,
44                 POSITION_Y = 2,
45                 POSITION_Z = 4,
46                 POSITION = POSITION_X|POSITION_Y|POSITION_Z,
47                 EULER_X = 8,
48                 EULER_Y = 16,
49                 EULER_Z = 32,
50                 EULER = EULER_X|EULER_Y|EULER_Z,
51                 SCALE_X = 64,
52                 SCALE_Y = 128,
53                 SCALE_Z = 256,
54                 SCALE = SCALE_X|SCALE_Y|SCALE_Z
55         };
56
57         typedef Geometry::Angle<float> Angle;
58         typedef LinAl::Vector<Angle, 3> AngleVector3;
59
60 private:
61         Vector3 position;
62         AngleVector3 euler;
63         Vector3 scale = { 1.0f, 1.0f, 1.0f };
64         ComponentMask mask = NONE;
65
66 public:
67         static Transform from_matrix(const Matrix &);
68
69         void set_position(const Vector3 &);
70         void set_euler(const AngleVector3 &);
71         void set_rotation(const Angle &, const Vector3 &);
72         void set_scale(float);
73         void set_scale(const Vector3 &);
74         const Vector3 &get_position() const { return position; }
75         const AngleVector3 &get_euler() const { return euler; }
76         const Vector3 &get_scale() const { return scale; }
77         ComponentMask get_mask() const { return mask; }
78
79         Matrix to_matrix() const;
80 };
81
82 inline Transform::ComponentMask operator&(Transform::ComponentMask m1, Transform::ComponentMask m2)
83 { return static_cast<Transform::ComponentMask>(static_cast<int>(m1)&static_cast<int>(m2)); }
84
85 inline Transform::ComponentMask operator|(Transform::ComponentMask m1, Transform::ComponentMask m2)
86 { return static_cast<Transform::ComponentMask>(static_cast<int>(m1)|static_cast<int>(m2)); }
87
88 inline Transform::ComponentMask operator^(Transform::ComponentMask m1, Transform::ComponentMask m2)
89 { return static_cast<Transform::ComponentMask>(static_cast<int>(m1)^static_cast<int>(m2)); }
90
91 inline Transform::ComponentMask operator~(Transform::ComponentMask m)
92 { return static_cast<Transform::ComponentMask>(~static_cast<int>(m)); }
93
94 } // namespace GL
95 } // namespace Msp
96
97 #endif