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