[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; |
---|
[3853] | 82 | /** \brief A virtual function that ticks the animation \param dt the time passed */ |
---|
[3852] | 83 | virtual void tick(float dt) = 0; |
---|
[3794] | 84 | |
---|
[3833] | 85 | /** |
---|
| 86 | \returns the BaseObject, this animation operates on |
---|
| 87 | */ |
---|
[3851] | 88 | BaseObject* getBaseObject(void) const {return baseObject;} |
---|
[3833] | 89 | |
---|
[3860] | 90 | /** \returns if the Animation should be deleted */ |
---|
| 91 | inline bool ifDelete(void) {return bDelete;} |
---|
| 92 | |
---|
[3782] | 93 | protected: |
---|
[3847] | 94 | Animation(void); |
---|
[3782] | 95 | |
---|
[3858] | 96 | void handleInfinity(void); |
---|
[3784] | 97 | // variables |
---|
[3853] | 98 | float localTime; //!< The Time passed since the beginning of the currentKeyFrame. |
---|
| 99 | ANIM_INFINITY postInfinity; //!< describing what the animation should do after the last keyframe. |
---|
[3794] | 100 | |
---|
[3833] | 101 | BaseObject* baseObject; //!< The same as object in the derived classes, but with reference to BaseObject |
---|
[3876] | 102 | unsigned int keyFrameCount; //!< The Count of KeyFrames. |
---|
[3982] | 103 | int keyFramesToPlay; //!< How many more Keyframes to play. if negative it will be ignored if 0 stop. |
---|
[3820] | 104 | bool bHandled; //!< If this Animation is handled by the AnimationPlayer. |
---|
[3853] | 105 | bool bRunning; //!< If the animation is running |
---|
[3860] | 106 | bool bDelete; //!< If true, the animation will be deleted through the AnimationPlayer. |
---|
[3782] | 107 | }; |
---|
| 108 | |
---|
| 109 | |
---|
[3833] | 110 | /**********************TEST*******************************/ |
---|
| 111 | class aTest |
---|
| 112 | { |
---|
| 113 | public: |
---|
| 114 | aTest() { last = 0.0;} |
---|
| 115 | ~aTest() {} |
---|
| 116 | void littleDebug(float f) { diff = f - last; printf("f=%f, diff=%f\n", f,diff); last = f;} |
---|
| 117 | private: |
---|
| 118 | float diff; |
---|
| 119 | float last; |
---|
| 120 | }; |
---|
| 121 | |
---|
| 122 | //aTest::aTest() {} |
---|
| 123 | //aTest::~aTest() {} |
---|
| 124 | |
---|
| 125 | //void aTest::littleDebug(float f) |
---|
| 126 | |
---|
| 127 | /**********************TEST*******************************/ |
---|
| 128 | |
---|
| 129 | |
---|
[3781] | 130 | #endif /* _ANIMATION_H */ |
---|