1 | /*! |
---|
2 | \file animation.h |
---|
3 | A Subclass for all animations in orxonox |
---|
4 | */ |
---|
5 | |
---|
6 | #ifndef _ANIMATION_H |
---|
7 | #define _ANIMATION_H |
---|
8 | |
---|
9 | #include "list.h" |
---|
10 | #include "base_object.h" |
---|
11 | #include "confincl.h" // must be here to determin the DEBUG-level |
---|
12 | |
---|
13 | // FORWARD DEFINITION |
---|
14 | |
---|
15 | //! An enumerator of Functions to describe the flow of the Animation |
---|
16 | /** |
---|
17 | \todo check with Patrick it of |
---|
18 | |
---|
19 | description in speed to the next keyframe: |
---|
20 | ANIM_CONSTANT: 0, infinity. |
---|
21 | ANIM_LINEAR: equal |
---|
22 | ANIM_SINE: fast, slow, fast |
---|
23 | ANIM_COSINE: slow, fast, slow |
---|
24 | ANIM_EXP: slow, fast |
---|
25 | ANIM_NEG_EXP: fast, slow |
---|
26 | ANIM_RANDOM: eratic |
---|
27 | |
---|
28 | deprecated QUADRATIC |
---|
29 | */ |
---|
30 | typedef enum ANIM_FUNCTION {ANIM_CONSTANT, |
---|
31 | ANIM_LINEAR, |
---|
32 | ANIM_SINE, |
---|
33 | ANIM_COSINE, |
---|
34 | ANIM_EXP, |
---|
35 | ANIM_NEG_EXP, |
---|
36 | ANIM_QUADRATIC, |
---|
37 | ANIM_RANDOM}; |
---|
38 | |
---|
39 | //! An enumerator describing what the animation should do after the last keyframe. |
---|
40 | /** |
---|
41 | ANIM_INF_CONSTANT stays at the end of the animation |
---|
42 | ANIM_INF_REPLAY loops back to the beginning and replays the animation |
---|
43 | ANIM_INF_REWIND loops back to the beginning and then stops the animation |
---|
44 | ANIM_INF_DELETE deletes the animation. !! THIS IS DANGEROUS !! only do this with non-class variables |
---|
45 | */ |
---|
46 | typedef enum ANIM_INFINITY {ANIM_INF_CONSTANT, |
---|
47 | ANIM_INF_REPLAY, |
---|
48 | ANIM_INF_REWIND, |
---|
49 | ANIM_INF_DELETE};//, ANIM_INF_LINEAR, ANIM_INF_PINGPONG; |
---|
50 | |
---|
51 | //! A Superclass for describing an animation (all animations will be derived from this one) |
---|
52 | /** implement in subclasses: |
---|
53 | * |
---|
54 | * De-/Constructor |
---|
55 | * Animation Functions |
---|
56 | * virtual tick |
---|
57 | * addKeyFrame |
---|
58 | * List of keyFrames |
---|
59 | * currentKeyFrame/nextKeyFrame |
---|
60 | * virtual rewind, to go to the first Keyframe. (other functions will call this one) |
---|
61 | */ |
---|
62 | class Animation |
---|
63 | { |
---|
64 | public: |
---|
65 | virtual ~Animation(void); |
---|
66 | void doNotHandle(void); |
---|
67 | |
---|
68 | void setInfinity(ANIM_INFINITY postInfinity = ANIM_INF_CONSTANT); |
---|
69 | |
---|
70 | void play(); // equals resume(); |
---|
71 | void stop(); |
---|
72 | void pause(); |
---|
73 | void replay(); |
---|
74 | //! A virtual function that should change to the first keyframe. |
---|
75 | virtual void rewind() = 0; |
---|
76 | /** \brief A virtual function that ticks the animation \param dt the time passed */ |
---|
77 | virtual void tick(float dt) = 0; |
---|
78 | |
---|
79 | /** |
---|
80 | \returns the BaseObject, this animation operates on |
---|
81 | */ |
---|
82 | BaseObject* getBaseObject(void) const {return baseObject;} |
---|
83 | |
---|
84 | /** \returns if the Animation should be deleted */ |
---|
85 | inline bool ifDelete(void) {return bDelete;} |
---|
86 | |
---|
87 | protected: |
---|
88 | Animation(void); |
---|
89 | |
---|
90 | void handleInfinity(void); |
---|
91 | // variables |
---|
92 | float localTime; //!< The Time passed since the beginning of the currentKeyFrame. |
---|
93 | ANIM_INFINITY postInfinity; //!< describing what the animation should do after the last keyframe. |
---|
94 | |
---|
95 | BaseObject* baseObject; //!< The same as object in the derived classes, but with reference to BaseObject |
---|
96 | bool bHasKeys; //!< If the animation has any keys at all. Needed to add the first keyframe (and delete the dummy). |
---|
97 | bool bHandled; //!< If this Animation is handled by the AnimationPlayer. |
---|
98 | bool bRunning; //!< If the animation is running |
---|
99 | bool bDelete; //!< If true, the animation will be deleted through the AnimationPlayer. |
---|
100 | }; |
---|
101 | |
---|
102 | |
---|
103 | /**********************TEST*******************************/ |
---|
104 | class aTest |
---|
105 | { |
---|
106 | public: |
---|
107 | aTest() { last = 0.0;} |
---|
108 | ~aTest() {} |
---|
109 | void littleDebug(float f) { diff = f - last; printf("f=%f, diff=%f\n", f,diff); last = f;} |
---|
110 | private: |
---|
111 | float diff; |
---|
112 | float last; |
---|
113 | }; |
---|
114 | |
---|
115 | //aTest::aTest() {} |
---|
116 | //aTest::~aTest() {} |
---|
117 | |
---|
118 | //void aTest::littleDebug(float f) |
---|
119 | |
---|
120 | /**********************TEST*******************************/ |
---|
121 | |
---|
122 | |
---|
123 | #endif /* _ANIMATION_H */ |
---|