Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/particles/quick_animation.h @ 8602

Last change on this file since 8602 was 8148, checked in by bensch, 19 years ago

trunk: output of EventListener Nicer

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