Transform::Transform():
position(0.0f, 0.0f, 0.0f),
euler(Angle::zero(), Angle::zero(), Angle::zero()),
- scale(1.0f, 1.0f, 1.0f)
+ scale(1.0f, 1.0f, 1.0f),
+ mask(NONE)
{ }
Transform Transform::from_matrix(const Matrix &matrix)
trn.scale = Vector3(m(0, 0), m(1, 1), m(2, 2));
+ trn.mask = POSITION|EULER|SCALE;
return trn;
}
void Transform::set_position(const Vector3 &p)
{
position = p;
+ mask = mask|POSITION;
}
void Transform::set_euler(const AngleVector3 &e)
{
euler = e;
+ mask = mask|EULER;
}
void Transform::set_rotation(const Angle &angle, const Vector3 &axis)
{
euler = from_matrix(Matrix::rotation(angle, axis)).euler;
+ mask = mask|EULER;
}
void Transform::set_scale(float s)
void Transform::set_scale(const Vector3 &s)
{
scale = s;
+ mask = mask|SCALE;
}
Matrix Transform::to_matrix() const
Transform::Loader::Loader(Transform &t):
DataFile::ObjectLoader<Transform>(t)
{
+ add("position_x", &Loader::position_x);
+ add("position_y", &Loader::position_y);
+ add("position_z", &Loader::position_z);
add("position", &Loader::position);
+ add("euler_x", &Loader::euler_x);
+ add("euler_y", &Loader::euler_y);
+ add("euler_z", &Loader::euler_z);
add("euler", &Loader::euler);
add("rotation", &Loader::rotation);
+ add("scale_x", &Loader::scale_x);
+ add("scale_y", &Loader::scale_y);
+ add("scale_z", &Loader::scale_z);
add("scale", &Loader::scale_uniform);
add("scale", &Loader::scale);
}
+void Transform::Loader::position_x(float x)
+{
+ obj.position.x = x;
+ obj.mask = obj.mask|POSITION_X;
+}
+
+void Transform::Loader::position_y(float y)
+{
+ obj.position.y = y;
+ obj.mask = obj.mask|POSITION_Y;
+}
+
+void Transform::Loader::position_z(float z)
+{
+ obj.position.z = z;
+ obj.mask = obj.mask|POSITION_Z;
+}
+
void Transform::Loader::position(float x, float y, float z)
{
obj.set_position(Vector3(x, y, z));
}
+void Transform::Loader::euler_x(float x)
+{
+ obj.euler.x = Angle::from_degrees(x);
+ obj.mask = obj.mask|EULER_X;
+}
+
+void Transform::Loader::euler_y(float y)
+{
+ obj.euler.y = Angle::from_degrees(y);
+ obj.mask = obj.mask|EULER_Y;
+}
+
+void Transform::Loader::euler_z(float z)
+{
+ obj.euler.z = Angle::from_degrees(z);
+ obj.mask = obj.mask|EULER_Z;
+}
+
void Transform::Loader::euler(float x, float y, float z)
{
obj.set_euler(AngleVector3(Angle::from_degrees(x), Angle::from_degrees(y), Angle::from_degrees(z)));
obj.set_rotation(Angle::from_degrees(a), Vector3(x, y, z));
}
+void Transform::Loader::scale_x(float x)
+{
+ obj.scale.x = x;
+ obj.mask = obj.mask|SCALE_X;
+}
+
+void Transform::Loader::scale_y(float y)
+{
+ obj.scale.y = y;
+ obj.mask = obj.mask|SCALE_Y;
+}
+
+void Transform::Loader::scale_z(float z)
+{
+ obj.scale.z = z;
+ obj.mask = obj.mask|SCALE_Z;
+}
+
void Transform::Loader::scale_uniform(float s)
{
obj.set_scale(s);
Loader(Transform &);
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;
Vector3 position;
AngleVector3 euler;
Vector3 scale;
+ ComponentMask mask;
public:
Transform();
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