[4597] | 1 | /*! |
---|
[5039] | 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 | |
---|
[5405] | 14 | // FORWARD DECLARATION |
---|
[3782] | 15 | |
---|
[3853] | 16 | //! An enumerator of Functions to describe the flow of the Animation |
---|
[3863] | 17 | /** |
---|
[4836] | 18 | @todo check with Patrick it of |
---|
[3863] | 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 | { |
---|
[5062] | 35 | ANIM_NULL = 0, |
---|
| 36 | ANIM_CONSTANT = 1, |
---|
| 37 | ANIM_LINEAR = 2, |
---|
| 38 | ANIM_SINE = 3, |
---|
| 39 | ANIM_COSINE = 4, |
---|
| 40 | ANIM_EXP = 5, |
---|
| 41 | ANIM_NEG_EXP = 6, |
---|
| 42 | ANIM_QUADRATIC = 7, |
---|
| 43 | ANIM_RANDOM = 8, |
---|
[4597] | 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: |
---|
[4746] | 77 | virtual ~Animation(); |
---|
[3794] | 78 | |
---|
| 79 | void setInfinity(ANIM_INFINITY postInfinity = ANIM_INF_CONSTANT); |
---|
| 80 | |
---|
| 81 | void play(); // equals resume(); |
---|
[3982] | 82 | void playNextKeyframes(int n = 1); |
---|
[3794] | 83 | void stop(); |
---|
| 84 | void pause(); |
---|
| 85 | void replay(); |
---|
[3853] | 86 | //! A virtual function that should change to the first keyframe. |
---|
[3797] | 87 | virtual void rewind() = 0; |
---|
[4485] | 88 | |
---|
[4837] | 89 | /** A virtual function that ticks the animation @param dt the time passed */ |
---|
[3852] | 90 | virtual void tick(float dt) = 0; |
---|
[3794] | 91 | |
---|
[4836] | 92 | /** @returns the BaseObject, this animation operates on */ |
---|
[4746] | 93 | BaseObject* getBaseObject() const { return this->baseObject; }; |
---|
[3833] | 94 | |
---|
[4836] | 95 | /** @returns if the Animation should be deleted */ |
---|
[4746] | 96 | inline bool ifDelete() { return bDelete; }; |
---|
[3860] | 97 | |
---|
[3782] | 98 | protected: |
---|
[4746] | 99 | Animation(); |
---|
[3782] | 100 | |
---|
[4746] | 101 | void handleInfinity(); |
---|
[4485] | 102 | |
---|
| 103 | protected: |
---|
[3784] | 104 | // variables |
---|
[4485] | 105 | float localTime; //!< The Time passed since the beginning of the currentKeyFrame. |
---|
| 106 | ANIM_INFINITY postInfinity; //!< describing what the animation should do after the last keyframe. |
---|
[3794] | 107 | |
---|
[4485] | 108 | BaseObject* baseObject; //!< The same as object in the derived classes, but with reference to BaseObject |
---|
| 109 | unsigned int keyFrameCount; //!< The Count of KeyFrames. |
---|
| 110 | int keyFramesToPlay; //!< How many more Keyframes to play. if negative it will be ignored if 0 stop. |
---|
| 111 | bool bRunning; //!< If the animation is running |
---|
| 112 | bool bDelete; //!< If true, the animation will be deleted through the AnimationPlayer. |
---|
[3782] | 113 | }; |
---|
| 114 | |
---|
| 115 | |
---|
[4485] | 116 | |
---|
| 117 | |
---|
[3833] | 118 | /**********************TEST*******************************/ |
---|
[4485] | 119 | //! a simple testClass for the animation |
---|
[3833] | 120 | class aTest |
---|
| 121 | { |
---|
| 122 | public: |
---|
[4485] | 123 | inline aTest() { last = 0.0;} |
---|
[4837] | 124 | /** a little debug information to show the results of this class @param f new value */ |
---|
[4485] | 125 | inline void littleDebug(float f) { diff = f - last; printf("f=%f, diff=%f\n", f,diff); last = f;} |
---|
[3833] | 126 | private: |
---|
[4485] | 127 | float diff; //!< difference from the last value |
---|
| 128 | float last; //!< the last calculated value |
---|
[3833] | 129 | }; |
---|
| 130 | |
---|
| 131 | //aTest::aTest() {} |
---|
| 132 | //aTest::~aTest() {} |
---|
| 133 | |
---|
| 134 | //void aTest::littleDebug(float f) |
---|
| 135 | |
---|
| 136 | /**********************TEST*******************************/ |
---|
| 137 | |
---|
| 138 | |
---|
[3781] | 139 | #endif /* _ANIMATION_H */ |
---|