]> git.tdb.fi Git - libs/gl.git/blob - source/transform.h
Allow texture mipmap levels to be specified in datafiles
[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_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;
64         ComponentMask mask;
65
66 public:
67         Transform();
68
69         static Transform from_matrix(const Matrix &);
70
71         void set_position(const Vector3 &);
72         void set_euler(const AngleVector3 &);
73         void set_rotation(const Angle &, const Vector3 &);
74         void set_scale(float);
75         void set_scale(const Vector3 &);
76         const Vector3 &get_position() const { return position; }
77         const AngleVector3 &get_euler() const { return euler; }
78         const Vector3 &get_scale() const { return scale; }
79         ComponentMask get_mask() const { return mask; }
80
81         Matrix to_matrix() const;
82 };
83
84 inline Transform::ComponentMask operator&(Transform::ComponentMask m1, Transform::ComponentMask m2)
85 { return static_cast<Transform::ComponentMask>(static_cast<int>(m1)&static_cast<int>(m2)); }
86
87 inline Transform::ComponentMask operator|(Transform::ComponentMask m1, Transform::ComponentMask m2)
88 { return static_cast<Transform::ComponentMask>(static_cast<int>(m1)|static_cast<int>(m2)); }
89
90 inline Transform::ComponentMask operator^(Transform::ComponentMask m1, Transform::ComponentMask m2)
91 { return static_cast<Transform::ComponentMask>(static_cast<int>(m1)^static_cast<int>(m2)); }
92
93 inline Transform::ComponentMask operator~(Transform::ComponentMask m)
94 { return static_cast<Transform::ComponentMask>(~static_cast<int>(m)); }
95
96 } // namespace GL
97 } // namespace Msp
98
99 #endif