[4597] | 1 | /*! |
---|
[3781] | 2 | \file animation.h |
---|
[3849] | 3 | A Subclass for all animations in orxonox |
---|
[3781] | 4 | */ |
---|
| 5 | |
---|
| 6 | #ifndef _ANIMATION_H |
---|
| 7 | #define _ANIMATION_H |
---|
| 8 | |
---|
[3795] | 9 | #include "list.h" |
---|
[3833] | 10 | #include "base_object.h" |
---|
[3863] | 11 | #include "confincl.h" // must be here to determin the DEBUG-level |
---|
[4381] | 12 | #include "debug.h" |
---|
[3833] | 13 | |
---|
[3782] | 14 | // FORWARD DEFINITION |
---|
| 15 | |
---|
[3853] | 16 | //! An enumerator of Functions to describe the flow of the Animation |
---|
[3863] | 17 | /** |
---|
| 18 | \todo check with Patrick it of |
---|
| 19 | |
---|
| 20 | description in speed to the next keyframe: |
---|
| 21 | ANIM_CONSTANT: 0, infinity. |
---|
| 22 | ANIM_LINEAR: equal |
---|
| 23 | ANIM_SINE: fast, slow, fast |
---|
| 24 | ANIM_COSINE: slow, fast, slow |
---|
[3867] | 25 | ANIM_EXP: slow, fast |
---|
| 26 | ANIM_NEG_EXP: fast, slow |
---|
[3863] | 27 | ANIM_RANDOM: eratic |
---|
[3978] | 28 | |
---|
| 29 | ANIM_NULL: !!DO NOT USE THIS!! only for internal handling |
---|
| 30 | |
---|
[3863] | 31 | deprecated QUADRATIC |
---|
| 32 | */ |
---|
[4597] | 33 | typedef enum ANIM_FUNCTION |
---|
| 34 | { |
---|
| 35 | ANIM_CONSTANT, |
---|
| 36 | ANIM_LINEAR, |
---|
| 37 | ANIM_SINE, |
---|
| 38 | ANIM_COSINE, |
---|
| 39 | ANIM_EXP, |
---|
| 40 | ANIM_NEG_EXP, |
---|
| 41 | ANIM_QUADRATIC, |
---|
| 42 | ANIM_RANDOM, |
---|
| 43 | ANIM_NULL |
---|
| 44 | }; |
---|
| 45 | |
---|
[3979] | 46 | #define ANIM_DEFAULT_FUNCTION ANIM_LINEAR //!< A default function to choose from the above set |
---|
[3787] | 47 | |
---|
[3853] | 48 | //! An enumerator describing what the animation should do after the last keyframe. |
---|
[3858] | 49 | /** |
---|
| 50 | ANIM_INF_CONSTANT stays at the end of the animation |
---|
[3863] | 51 | ANIM_INF_REPLAY loops back to the beginning and replays the animation |
---|
| 52 | ANIM_INF_REWIND loops back to the beginning and then stops the animation |
---|
| 53 | ANIM_INF_DELETE deletes the animation. !! THIS IS DANGEROUS !! only do this with non-class variables |
---|
[3858] | 54 | */ |
---|
[4597] | 55 | typedef enum ANIM_INFINITY |
---|
| 56 | { |
---|
| 57 | ANIM_INF_CONSTANT, |
---|
| 58 | ANIM_INF_REPLAY, |
---|
| 59 | ANIM_INF_REWIND, |
---|
| 60 | ANIM_INF_DELETE |
---|
| 61 | }; //, ANIM_INF_LINEAR, ANIM_INF_PINGPONG}; |
---|
[3543] | 62 | |
---|
[3853] | 63 | //! A Superclass for describing an animation (all animations will be derived from this one) |
---|
| 64 | /** implement in subclasses: |
---|
[4597] | 65 | * |
---|
[3853] | 66 | * De-/Constructor |
---|
| 67 | * Animation Functions |
---|
| 68 | * virtual tick |
---|
[3860] | 69 | * addKeyFrame |
---|
[3853] | 70 | * List of keyFrames |
---|
| 71 | * currentKeyFrame/nextKeyFrame |
---|
| 72 | * virtual rewind, to go to the first Keyframe. (other functions will call this one) |
---|
| 73 | */ |
---|
[4597] | 74 | class Animation : public BaseObject |
---|
[3782] | 75 | { |
---|
[3785] | 76 | public: |
---|
[3847] | 77 | virtual ~Animation(void); |
---|
[3820] | 78 | void doNotHandle(void); |
---|
[3794] | 79 | |
---|
| 80 | void setInfinity(ANIM_INFINITY postInfinity = ANIM_INF_CONSTANT); |
---|
| 81 | |
---|
| 82 | void play(); // equals resume(); |
---|
[3982] | 83 | void playNextKeyframes(int n = 1); |
---|
[3794] | 84 | void stop(); |
---|
| 85 | void pause(); |
---|
| 86 | void replay(); |
---|
[3853] | 87 | //! A virtual function that should change to the first keyframe. |
---|
[3797] | 88 | virtual void rewind() = 0; |
---|
[4485] | 89 | |
---|
[3853] | 90 | /** \brief A virtual function that ticks the animation \param dt the time passed */ |
---|
[3852] | 91 | virtual void tick(float dt) = 0; |
---|
[3794] | 92 | |
---|
[4485] | 93 | /** \returns the BaseObject, this animation operates on */ |
---|
| 94 | BaseObject* getBaseObject(void) const { return this->baseObject; }; |
---|
[3833] | 95 | |
---|
[3860] | 96 | /** \returns if the Animation should be deleted */ |
---|
[4485] | 97 | inline bool ifDelete(void) { return bDelete; }; |
---|
[3860] | 98 | |
---|
[3782] | 99 | protected: |
---|
[3847] | 100 | Animation(void); |
---|
[3782] | 101 | |
---|
[3858] | 102 | void handleInfinity(void); |
---|
[4485] | 103 | |
---|
| 104 | protected: |
---|
[3784] | 105 | // variables |
---|
[4485] | 106 | float localTime; //!< The Time passed since the beginning of the currentKeyFrame. |
---|
| 107 | ANIM_INFINITY postInfinity; //!< describing what the animation should do after the last keyframe. |
---|
[3794] | 108 | |
---|
[4485] | 109 | BaseObject* baseObject; //!< The same as object in the derived classes, but with reference to BaseObject |
---|
| 110 | unsigned int keyFrameCount; //!< The Count of KeyFrames. |
---|
| 111 | int keyFramesToPlay; //!< How many more Keyframes to play. if negative it will be ignored if 0 stop. |
---|
| 112 | bool bHandled; //!< If this Animation is handled by the AnimationPlayer. |
---|
| 113 | bool bRunning; //!< If the animation is running |
---|
| 114 | bool bDelete; //!< If true, the animation will be deleted through the AnimationPlayer. |
---|
[3782] | 115 | }; |
---|
| 116 | |
---|
| 117 | |
---|
[4485] | 118 | |
---|
| 119 | |
---|
[3833] | 120 | /**********************TEST*******************************/ |
---|
[4485] | 121 | //! a simple testClass for the animation |
---|
[3833] | 122 | class aTest |
---|
| 123 | { |
---|
| 124 | public: |
---|
[4485] | 125 | inline aTest() { last = 0.0;} |
---|
| 126 | /** \brief a little debug information to show the results of this class \param f new value */ |
---|
| 127 | inline void littleDebug(float f) { diff = f - last; printf("f=%f, diff=%f\n", f,diff); last = f;} |
---|
[3833] | 128 | private: |
---|
[4485] | 129 | float diff; //!< difference from the last value |
---|
| 130 | float last; //!< the last calculated value |
---|
[3833] | 131 | }; |
---|
| 132 | |
---|
| 133 | //aTest::aTest() {} |
---|
| 134 | //aTest::~aTest() {} |
---|
| 135 | |
---|
| 136 | //void aTest::littleDebug(float f) |
---|
| 137 | |
---|
| 138 | /**********************TEST*******************************/ |
---|
| 139 | |
---|
| 140 | |
---|
[3781] | 141 | #endif /* _ANIMATION_H */ |
---|