From a4549c55a6d47129bd9e42c6a49a671b759ce6d9 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Tue, 4 Jun 2019 17:13:59 +0300 Subject: [PATCH] Store a Transform in keyframes instead of a Matrix This is the first step towards curve-based animations and finer control over which values are animated. --- source/keyframe.cpp | 20 +++++++++++--------- source/keyframe.h | 7 +++++-- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/source/keyframe.cpp b/source/keyframe.cpp index 708fa22b..8eba1729 100644 --- a/source/keyframe.cpp +++ b/source/keyframe.cpp @@ -1,7 +1,6 @@ #include #include "keyframe.h" #include "pose.h" -#include "transform.h" using namespace std; @@ -15,9 +14,14 @@ KeyFrame::KeyFrame() KeyFrame::~KeyFrame() { } +void KeyFrame::set_transform(const Transform &t) +{ + transform = t; +} + void KeyFrame::set_matrix(const Matrix &m) { - matrix = m; + transform = Transform::from_matrix(m); } void KeyFrame::set_pose(const Pose &p) @@ -78,29 +82,27 @@ void KeyFrame::Loader::pose_inline() void KeyFrame::Loader::position(float x, float y, float z) { - obj.matrix.translate(x, y, z); + obj.transform.set_position(Vector3(x, y, z)); } void KeyFrame::Loader::rotation(float a, float x, float y, float z) { - obj.matrix.rotate_deg(a, x, y, z); + obj.transform.set_rotation(Transform::Angle::from_degrees(a), Vector3(x, y, z)); } void KeyFrame::Loader::scaling_uniform(float s) { - obj.matrix.scale(s); + obj.transform.set_scale(s); } void KeyFrame::Loader::scaling(float x, float y, float z) { - obj.matrix.scale(x, y, z); + obj.transform.set_scale(Vector3(x, y, z)); } void KeyFrame::Loader::transform() { - Transform trn; - load_sub(trn); - obj.matrix = trn.to_matrix(); + load_sub(obj.transform); } void KeyFrame::Loader::uniforms() diff --git a/source/keyframe.h b/source/keyframe.h index 88e85214..4b985ca7 100644 --- a/source/keyframe.h +++ b/source/keyframe.h @@ -4,6 +4,7 @@ #include #include #include "matrix.h" +#include "transform.h" namespace Msp { namespace GL { @@ -57,7 +58,7 @@ public: typedef std::map UniformMap; private: - Matrix matrix; + Transform transform; UniformMap uniforms; RefPtr pose; @@ -65,9 +66,11 @@ public: KeyFrame(); ~KeyFrame(); + void set_transform(const Transform &); void set_matrix(const Matrix &); void set_pose(const Pose &); - const Matrix &get_matrix() const { return matrix; } + const Transform &get_transform() const { return transform; } + Matrix get_matrix() const { return transform.to_matrix(); } const UniformMap &get_uniforms() const { return uniforms; } const Pose *get_pose() const { return pose.get(); } }; -- 2.45.2