-/* $Id$
+#ifndef MSP_GL_TRANSFORM_H_
+#define MSP_GL_TRANSFORM_H_
-This file is part of libmspgl
-Copyright © 2007 Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
+#include <msp/datafile/objectloader.h>
+#include "matrix.h"
+
+namespace Msp {
+namespace GL {
+
+/**
+Stores a coordinate space transform as individual components. Primarily
+intended for loading data from external sources. At runtime transforms
+should generally be stored as matrices.
*/
+class Transform
+{
+public:
+ class Loader: public DataFile::ObjectLoader<Transform>
+ {
+ public:
+ Loader(Transform &);
-#include "matrix.h"
+ private:
+ void position_x(float);
+ void position_y(float);
+ void position_z(float);
+ void position(float, float, float);
+ void euler_x(float);
+ void euler_y(float);
+ void euler_z(float);
+ void euler(float, float, float);
+ void rotation(float, float, float, float);
+ void scale_x(float);
+ void scale_y(float);
+ void scale_z(float);
+ void scale_uniform(float);
+ void scale(float, float, float);
+ };
+
+ enum ComponentMask
+ {
+ NONE = 0,
+ POSITION_X = 1,
+ POSITION_Y = 2,
+ POSITION_Z = 4,
+ POSITION = POSITION_X|POSITION_Y|POSITION_Z,
+ EULER_X = 8,
+ EULER_Y = 16,
+ EULER_Z = 32,
+ EULER = EULER_X|EULER_Y|EULER_Z,
+ SCALE_X = 64,
+ SCALE_Y = 128,
+ SCALE_Z = 256,
+ SCALE = SCALE_X|SCALE_Y|SCALE_Z
+ };
+
+ typedef Geometry::Angle<float> Angle;
+ typedef LinAl::Vector<Angle, 3> AngleVector3;
+
+private:
+ Vector3 position;
+ AngleVector3 euler;
+ Vector3 scale;
+ ComponentMask mask;
+
+public:
+ Transform();
+
+ static Transform from_matrix(const Matrix &);
+
+ void set_position(const Vector3 &);
+ void set_euler(const AngleVector3 &);
+ void set_rotation(const Angle &, const Vector3 &);
+ void set_scale(float);
+ void set_scale(const Vector3 &);
+ const Vector3 &get_position() const { return position; }
+ const AngleVector3 &get_euler() const { return euler; }
+ const Vector3 &get_scale() const { return scale; }
+ ComponentMask get_mask() const { return mask; }
+
+ Matrix to_matrix() const;
+};
+
+inline Transform::ComponentMask operator&(Transform::ComponentMask m1, Transform::ComponentMask m2)
+{ return static_cast<Transform::ComponentMask>(static_cast<int>(m1)&static_cast<int>(m2)); }
+
+inline Transform::ComponentMask operator|(Transform::ComponentMask m1, Transform::ComponentMask m2)
+{ return static_cast<Transform::ComponentMask>(static_cast<int>(m1)|static_cast<int>(m2)); }
+
+inline Transform::ComponentMask operator^(Transform::ComponentMask m1, Transform::ComponentMask m2)
+{ return static_cast<Transform::ComponentMask>(static_cast<int>(m1)^static_cast<int>(m2)); }
+
+inline Transform::ComponentMask operator~(Transform::ComponentMask m)
+{ return static_cast<Transform::ComponentMask>(~static_cast<int>(m)); }
+
+} // namespace GL
+} // namespace Msp
+
+#endif