1 | /*! |
---|
2 | * @file quick_animation.h |
---|
3 | * Definition of the QuickAnimation-class |
---|
4 | |
---|
5 | */ |
---|
6 | |
---|
7 | #ifndef _QUICK_ANIMATION_H |
---|
8 | #define _QUICK_ANIMATION_H |
---|
9 | |
---|
10 | #include <vector> |
---|
11 | // FORWARD DECLARATION |
---|
12 | |
---|
13 | //! A class for that linearely interpolates between multiple values. |
---|
14 | /** |
---|
15 | * QuickAnimation is a Class that creates a LookupTable with |
---|
16 | * position between [0.0f - 1.0f] so that one can resolve the |
---|
17 | * given Value. |
---|
18 | */ |
---|
19 | class QuickAnimation |
---|
20 | { |
---|
21 | public: |
---|
22 | QuickAnimation(unsigned int resolution = 100); |
---|
23 | virtual ~QuickAnimation(); |
---|
24 | |
---|
25 | bool addKey(float position, float value); |
---|
26 | |
---|
27 | bool changeValueKey(unsigned int keyFrameNumber, float newValue); |
---|
28 | bool changeValue(float position, float newValue, float region = 0.04f); |
---|
29 | |
---|
30 | bool removeKey(unsigned int keyFrameNumber); |
---|
31 | bool remove(float position, float region = 0.04f); |
---|
32 | |
---|
33 | bool moveKey(unsigned int keyFrameNumber, float newPosition, float newValue); |
---|
34 | bool moveKey(unsigned int keyFrameNumber, float newPosition); |
---|
35 | bool move(float oldPosition, float newPosition, float newValue, float region = 0.04f); |
---|
36 | bool move(float oldPosition, float newPosition, float region = 0.04f); |
---|
37 | |
---|
38 | int getKeyAt(float position, float region = 0.04f); |
---|
39 | |
---|
40 | /** |
---|
41 | * @brief returns the value of the animation at a certain position |
---|
42 | * @param value returns the calculated value. |
---|
43 | * @param position The position to get the Value from. |
---|
44 | */ |
---|
45 | void QuickAnimation::getValue(float& value, float position) const |
---|
46 | { |
---|
47 | value = this->lookupValues[int(position*this->lookupValues.size())]; |
---|
48 | } |
---|
49 | |
---|
50 | /** |
---|
51 | * @brief returns the value of the animation at a certain position |
---|
52 | * @param position the position to get the value from :) |
---|
53 | * @returns the calculated Value. |
---|
54 | */ |
---|
55 | float QuickAnimation::getValue(float position) const |
---|
56 | { |
---|
57 | return this->lookupValues[int(position*this->lookupValues.size())]; |
---|
58 | } |
---|
59 | |
---|
60 | void debug() const; |
---|
61 | |
---|
62 | private: |
---|
63 | void rebuild(); |
---|
64 | |
---|
65 | private: |
---|
66 | //! a simple struct that stores keyframes for the QuickAnimation-Class. |
---|
67 | struct QuickKeyFrame |
---|
68 | { |
---|
69 | //! Creates a new QuickKeyFrame with @param position position @param value value */ |
---|
70 | QuickKeyFrame(float position, float value) : position(position), value(value) {}; |
---|
71 | float value; //!< The value of this KeyFrame |
---|
72 | float position; //!< The position of thies KeyFrame |
---|
73 | |
---|
74 | static bool sortPositionPredicate(const QuickKeyFrame& key1, const QuickKeyFrame& key2); |
---|
75 | static bool sortValuePredicate(const QuickKeyFrame& key1, const QuickKeyFrame& key2); |
---|
76 | }; |
---|
77 | |
---|
78 | std::vector<QuickKeyFrame> keyFrames; //!< An Array of KeyFrames. |
---|
79 | std::vector<float> lookupValues; //!< The lookup-table where the values are stored. |
---|
80 | }; |
---|
81 | |
---|
82 | #endif /* _QUICK_ANIMATION_H */ |
---|