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