Rendu
A lightweight rendering engine for experimentations
Loading...
Searching...
No Matches
Animation.hpp
1#pragma once
2
3#include "system/Codable.hpp"
4#include "Common.hpp"
5
9class Animation {
10public:
12 enum class Frame {
13 MODEL,
14 WORLD
15 };
16
23 virtual glm::mat4 apply(const glm::mat4 & m, double fullTime, double frameTime) = 0;
24
31 virtual glm::vec4 apply(const glm::vec4 & v, double fullTime, double frameTime) = 0;
32
36 virtual KeyValues encode() const;
37
39 virtual ~Animation() = default;
40
42 Animation(const Animation &) = delete;
43
47 Animation & operator=(const Animation &) = delete;
48
50 Animation(Animation &&) = delete;
51
56
61 static std::vector<std::shared_ptr<Animation>> decode(const std::vector<KeyValues> & params);
62
67 static std::vector<KeyValues> encode(const std::vector<std::shared_ptr<Animation>> & anims);
68
69protected:
70
72 Animation() = default;
73
78 Animation(Frame frame, float speed);
79
88 bool decodeBase(const KeyValues & params);
89
91 float _speed = 0.0f;
92};
93
97class Rotation final : public Animation {
98public:
100 Rotation() = default;
101
107 Rotation(const glm::vec3 & axis, float speed, Frame frame);
108
115 glm::mat4 apply(const glm::mat4 & m, double fullTime, double frameTime) override;
116
123 glm::vec4 apply(const glm::vec4 & v, double fullTime, double frameTime) override;
124
133 bool decode(const KeyValues & params);
134
138 KeyValues encode() const override;
139
140private:
141
142 glm::vec3 _axis = glm::vec3(1.0f, 0.0f, 0.0f);
143};
144
148class BackAndForth final : public Animation {
149public:
151 BackAndForth() = default;
152
159 BackAndForth(const glm::vec3 & axis, float speed, float amplitude, Frame frame);
160
167 glm::mat4 apply(const glm::mat4 & m, double fullTime, double frameTime) override;
168
175 glm::vec4 apply(const glm::vec4 & v, double fullTime, double frameTime) override;
176
185 bool decode(const KeyValues & params);
186
190 KeyValues encode() const override;
191
192private:
193
194 glm::vec3 _axis = glm::vec3(1.0f, 0.0f, 0.0f);
195 float _amplitude = 0.0f;
196 double _previousAbscisse = 0.0f;
197};
An animation is a transformation evaluated at each frame and applied to an object.
Definition: Animation.hpp:9
bool decodeBase(const KeyValues &params)
Definition: Animation.cpp:41
Animation & operator=(const Animation &)=delete
Animation & operator=(Animation &&)=delete
static std::vector< std::shared_ptr< Animation > > decode(const std::vector< KeyValues > &params)
Definition: Animation.cpp:7
Animation(Animation &&)=delete
Animation()=default
virtual glm::vec4 apply(const glm::vec4 &v, double fullTime, double frameTime)=0
virtual KeyValues encode() const
Definition: Animation.cpp:51
virtual glm::mat4 apply(const glm::mat4 &m, double fullTime, double frameTime)=0
virtual ~Animation()=default
Animation(const Animation &)=delete
Frame
Frame in which the transformation shoud be applied.
Definition: Animation.hpp:12
@ WORLD
World space (left multiplication)
@ MODEL
Model space (right multiplication)
Frame _frame
The frame of transformation.
Definition: Animation.hpp:90
float _speed
Speed of the animation.
Definition: Animation.hpp:91
Translate an object back and forth along a direction.
Definition: Animation.hpp:148
glm::mat4 apply(const glm::mat4 &m, double fullTime, double frameTime) override
Definition: Animation.cpp:97
BackAndForth()=default
KeyValues encode() const override
Definition: Animation.cpp:131
double _previousAbscisse
Position on the path at the previous frame.
Definition: Animation.hpp:196
bool decode(const KeyValues &params)
Definition: Animation.cpp:116
float _amplitude
Amplitude of the translation (maximum distance).
Definition: Animation.hpp:195
glm::vec3 _axis
Translation direction.
Definition: Animation.hpp:194
Rotate an object around an axis.
Definition: Animation.hpp:97
bool decode(const KeyValues &params)
Definition: Animation.cpp:73
glm::vec3 _axis
Rotation axis.
Definition: Animation.hpp:142
Rotation()=default
glm::mat4 apply(const glm::mat4 &m, double fullTime, double frameTime) override
Definition: Animation.cpp:63
KeyValues encode() const override
Definition: Animation.cpp:84
Represent a key-values tuple.
Definition: Config.hpp:9