]> git.tdb.fi Git - libs/gl.git/blob - source/transform.h
Add a class to unify loading coordinate transforms
[libs/gl.git] / source / 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(float, float, float);
25                 void euler(float, float, float);
26                 void rotation(float, float, float, float);
27                 void scale_uniform(float);
28                 void scale(float, float, float);
29         };
30
31         typedef Geometry::Angle<float> Angle;
32         typedef LinAl::Vector<Angle, 3> AngleVector3;
33
34 private:
35         Vector3 position;
36         AngleVector3 euler;
37         Vector3 scale;
38
39 public:
40         Transform();
41
42         void set_position(const Vector3 &);
43         void set_euler(const AngleVector3 &);
44         void set_scale(const Vector3 &);
45         const Vector3 &get_position() const { return position; }
46         const AngleVector3 &get_euler() const { return euler; }
47         const Vector3 &get_scale() const { return scale; }
48
49         Matrix to_matrix() const;
50 };
51
52 } // namespace GL
53 } // namespace Msp
54
55 #endif