Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7333 in orxonox.OLD for trunk/src/lib/particles/quick_animation.h


Ignore:
Timestamp:
Apr 18, 2006, 8:29:51 PM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: Totally new QuickAnimation. This should be much faster, but it isn't … this again shows, that most of the Time the processor is used on the Draw functions….

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/particles/quick_animation.h

    r5405 r7333  
    88#define _QUICK_ANIMATION_H
    99
    10 #include "base_object.h"
    11 
     10#include <vector>
    1211// FORWARD DECLARATION
    13 
    14 
    15 
    1612
    1713//! A class for that linearely interpolates between multiple values.
    1814/**
    19    to be quick this only has the capability to store very little date
     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 */
     19class QuickAnimation
     20{
     21public:
     22  QuickAnimation(unsigned int resolution = 100);
     23  virtual ~QuickAnimation();
    2024
    21    this class is optimized for a raising value. eg. 100 particles sorted
    22    by age.
    23 */
    24 class QuickAnimation : public BaseObject {
     25  bool addKey(float position, float value);
    2526
    26  public:
     27  bool changeValueKey(unsigned int keyFrameNumber, float newValue);
     28  bool changeValue(float position, float newValue, float region = 0.04f);
    2729
     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;
     61private:
     62  void rebuild();
     63
     64private:
    2865  //! a simple struct that stores keyframes for the QuickAnimation-Class.
    2966  struct QuickKeyFrame
    3067  {
    31     float            value;             //!< The starting value of this KeyFrame
    32     float            position;          //!< The end position of thies KeyFrame
     68    //! Creates a new QuickKeyFrame with @param position position @param value value */
     69    QuickKeyFrame(float position, float value) :  position(position), value(value) {};
     70    float            value;             //!< The value of this KeyFrame
     71    float            position;          //!< The position of thies KeyFrame
    3372
    34     QuickKeyFrame*   next;              //!< The next Animation
    35     QuickKeyFrame*   prev;              //!< The previous QuickKeyFrame
     73    static bool sortPositionPredicate(const QuickKeyFrame& key1, const QuickKeyFrame& key2);
     74    static bool sortValuePredicate(const QuickKeyFrame& key1, const QuickKeyFrame& key2);
    3675  };
    3776
    38   QuickAnimation();
    39   virtual ~QuickAnimation();
    40 
    41   void addEntry(float position, float value);
    42   void changeEntry(float position, float value, float region = .04);
    43 
    44   void removeEntry(float position);
    45   /** @todo implemente those functions
    46       bool moveEntry(float position);
    47   */
    48 
    49   float getValue(float position);
    50 
    51   void debug();
    52 
    53  private:
    54   QuickKeyFrame*       first;          //!< The first KeyFrame in a Sequence of Keyframes.
    55   QuickKeyFrame*       current;        //!< The currently selected KeyFrame.
    56   unsigned int         count;          //!< How many Keyframes the QuickAnimation has.
     77  std::vector<QuickKeyFrame>    keyFrames;              //!< An Array of KeyFrames.
     78  std::vector<float>            lookupValues;           //!< The lookup-table where the values are stored.
    5779};
    5880
Note: See TracChangeset for help on using the changeset viewer.