[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" |
---|
| 11 | |
---|
[3782] | 12 | // FORWARD DEFINITION |
---|
| 13 | |
---|
[3853] | 14 | //! An enumerator of Functions to describe the flow of the Animation |
---|
[3784] | 15 | typedef enum ANIM_FUNCTION {ANIM_CONSTANT, |
---|
| 16 | ANIM_LINEAR, |
---|
| 17 | ANIM_SINE, |
---|
[3825] | 18 | ANIM_COSINE, |
---|
| 19 | ANIM_EXP, |
---|
| 20 | ANIM_NEG_EXP, |
---|
| 21 | ANIM_QUADRATIC, |
---|
[3784] | 22 | ANIM_RANDOM}; |
---|
[3787] | 23 | |
---|
[3853] | 24 | //! An enumerator describing what the animation should do after the last keyframe. |
---|
[3858] | 25 | /** |
---|
| 26 | ANIM_INF_CONSTANT stays at the end of the animation |
---|
| 27 | ANIM_INF_REWIND loops back to the beginning and replays the animation |
---|
| 28 | */ |
---|
[3784] | 29 | typedef enum ANIM_INFINITY {ANIM_INF_CONSTANT, |
---|
[3858] | 30 | ANIM_INF_REPLAY, |
---|
| 31 | ANIM_INF_DELETE};//, ANIM_INF_LINEAR, ANIM_INF_PINGPONG; |
---|
[3543] | 32 | |
---|
[3853] | 33 | //! A Struct for Keyframes that simply hold a float |
---|
[3848] | 34 | typedef struct KeyFrameF |
---|
[3784] | 35 | { |
---|
[3853] | 36 | float duration; //!< duration of this keyframe |
---|
| 37 | float value; //!< value of this keyframe |
---|
| 38 | ANIM_FUNCTION animFunc; //!< with whitch function to iterate to the next KeyFrameF |
---|
[3784] | 39 | }; |
---|
| 40 | |
---|
[3853] | 41 | //! A Superclass for describing an animation (all animations will be derived from this one) |
---|
| 42 | /** implement in subclasses: |
---|
| 43 | * |
---|
| 44 | * De-/Constructor |
---|
| 45 | * Animation Functions |
---|
| 46 | * virtual tick |
---|
[3860] | 47 | * addKeyFrame |
---|
[3853] | 48 | * List of keyFrames |
---|
| 49 | * currentKeyFrame/nextKeyFrame |
---|
| 50 | * virtual rewind, to go to the first Keyframe. (other functions will call this one) |
---|
| 51 | */ |
---|
[3847] | 52 | class Animation |
---|
[3782] | 53 | { |
---|
[3785] | 54 | public: |
---|
[3847] | 55 | virtual ~Animation(void); |
---|
[3820] | 56 | void doNotHandle(void); |
---|
[3794] | 57 | |
---|
| 58 | void setInfinity(ANIM_INFINITY postInfinity = ANIM_INF_CONSTANT); |
---|
| 59 | |
---|
| 60 | void play(); // equals resume(); |
---|
| 61 | void stop(); |
---|
| 62 | void pause(); |
---|
| 63 | void replay(); |
---|
[3853] | 64 | //! A virtual function that should change to the first keyframe. |
---|
[3797] | 65 | virtual void rewind() = 0; |
---|
[3853] | 66 | /** \brief A virtual function that ticks the animation \param dt the time passed */ |
---|
[3852] | 67 | virtual void tick(float dt) = 0; |
---|
[3794] | 68 | |
---|
[3833] | 69 | /** |
---|
| 70 | \returns the BaseObject, this animation operates on |
---|
| 71 | */ |
---|
[3851] | 72 | BaseObject* getBaseObject(void) const {return baseObject;} |
---|
[3833] | 73 | |
---|
[3860] | 74 | /** \returns if the Animation should be deleted */ |
---|
| 75 | inline bool ifDelete(void) {return bDelete;} |
---|
| 76 | |
---|
[3782] | 77 | protected: |
---|
[3847] | 78 | Animation(void); |
---|
[3782] | 79 | |
---|
[3858] | 80 | void handleInfinity(void); |
---|
[3784] | 81 | // variables |
---|
[3853] | 82 | float localTime; //!< The Time passed since the beginning of the currentKeyFrame. |
---|
| 83 | ANIM_INFINITY postInfinity; //!< describing what the animation should do after the last keyframe. |
---|
[3794] | 84 | |
---|
[3833] | 85 | BaseObject* baseObject; //!< The same as object in the derived classes, but with reference to BaseObject |
---|
[3853] | 86 | bool bHasKeys; //!< If the animation has any keys at all. Needed to add the first keyframe (and delete the dummy). |
---|
[3820] | 87 | bool bHandled; //!< If this Animation is handled by the AnimationPlayer. |
---|
[3853] | 88 | bool bRunning; //!< If the animation is running |
---|
[3860] | 89 | bool bDelete; //!< If true, the animation will be deleted through the AnimationPlayer. |
---|
[3782] | 90 | }; |
---|
| 91 | |
---|
| 92 | |
---|
[3833] | 93 | /**********************TEST*******************************/ |
---|
| 94 | class aTest |
---|
| 95 | { |
---|
| 96 | public: |
---|
| 97 | aTest() { last = 0.0;} |
---|
| 98 | ~aTest() {} |
---|
| 99 | void littleDebug(float f) { diff = f - last; printf("f=%f, diff=%f\n", f,diff); last = f;} |
---|
| 100 | private: |
---|
| 101 | float diff; |
---|
| 102 | float last; |
---|
| 103 | }; |
---|
| 104 | |
---|
| 105 | //aTest::aTest() {} |
---|
| 106 | //aTest::~aTest() {} |
---|
| 107 | |
---|
| 108 | //void aTest::littleDebug(float f) |
---|
| 109 | |
---|
| 110 | /**********************TEST*******************************/ |
---|
| 111 | |
---|
| 112 | |
---|
[3781] | 113 | #endif /* _ANIMATION_H */ |
---|