From: Mikko Rasa Date: Tue, 11 Jun 2019 08:03:24 +0000 (+0300) Subject: Keep track of which components have been set in Transform X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=8bc776f177c7cf9d0c6fd9590273f086d38c23ca;p=libs%2Fgl.git Keep track of which components have been set in Transform Also allow individual vector elements to be specified in datafiles. --- diff --git a/source/transform.cpp b/source/transform.cpp index ea5839fb..6862221b 100644 --- a/source/transform.cpp +++ b/source/transform.cpp @@ -6,7 +6,8 @@ namespace GL { 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) @@ -23,22 +24,26 @@ 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) @@ -49,6 +54,7 @@ void Transform::set_scale(float s) void Transform::set_scale(const Vector3 &s) { scale = s; + mask = mask|SCALE; } Matrix Transform::to_matrix() const @@ -66,18 +72,63 @@ Matrix Transform::to_matrix() const Transform::Loader::Loader(Transform &t): DataFile::ObjectLoader(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))); @@ -88,6 +139,24 @@ void Transform::Loader::rotation(float a, float x, float y, float 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); diff --git a/source/transform.h b/source/transform.h index 01c783bd..1d0aeddd 100644 --- a/source/transform.h +++ b/source/transform.h @@ -21,13 +21,39 @@ public: 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 Angle; typedef LinAl::Vector AngleVector3; @@ -35,6 +61,7 @@ private: Vector3 position; AngleVector3 euler; Vector3 scale; + ComponentMask mask; public: Transform(); @@ -49,10 +76,23 @@ public: 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(static_cast(m1)&static_cast(m2)); } + +inline Transform::ComponentMask operator|(Transform::ComponentMask m1, Transform::ComponentMask m2) +{ return static_cast(static_cast(m1)|static_cast(m2)); } + +inline Transform::ComponentMask operator^(Transform::ComponentMask m1, Transform::ComponentMask m2) +{ return static_cast(static_cast(m1)^static_cast(m2)); } + +inline Transform::ComponentMask operator~(Transform::ComponentMask m) +{ return static_cast(~static_cast(m)); } + } // namespace GL } // namespace Msp