1 | /*! |
---|
2 | \file simple_animation.h |
---|
3 | \brief A class to interpolate the movement of an object following descrete points in room and time |
---|
4 | \todo implement it |
---|
5 | |
---|
6 | This class has been done to animate some movement, works best for short |
---|
7 | distances. |
---|
8 | */ |
---|
9 | |
---|
10 | #ifndef _SIMPLE_ANIMATION_H |
---|
11 | #define _SIMPLE_ANIMATION_H |
---|
12 | |
---|
13 | #include "base_object.h" |
---|
14 | #include "list.h" |
---|
15 | #include "animation.h" |
---|
16 | |
---|
17 | |
---|
18 | class Vector; |
---|
19 | class Quaternion; |
---|
20 | class WorldEntity; |
---|
21 | class PNode; |
---|
22 | |
---|
23 | typedef enum movementMode{LINEAR=0, EXP, NEG_EXP, SIN, COS, QUADRATIC}; |
---|
24 | typedef enum animationMode{SINGLE=0, LOOP}; |
---|
25 | #define DEFAULT_ANIMATION_MODE LINEAR |
---|
26 | |
---|
27 | |
---|
28 | //! KeyFrame Struct |
---|
29 | /** |
---|
30 | This represents one point with direction of the animation |
---|
31 | */ |
---|
32 | typedef struct KeyFrame3D { |
---|
33 | Vector* position; |
---|
34 | Quaternion* direction; |
---|
35 | WorldEntity* object; |
---|
36 | float time; |
---|
37 | movementMode mode; |
---|
38 | }; |
---|
39 | |
---|
40 | //! Animation Struct |
---|
41 | /** |
---|
42 | This represents an animation for a object |
---|
43 | */ |
---|
44 | class Animation3D : public Animation |
---|
45 | { |
---|
46 | public: |
---|
47 | Animation3D(void); |
---|
48 | virtual ~Animation3D(void); |
---|
49 | |
---|
50 | virtual void rewind(void); |
---|
51 | |
---|
52 | void addKeyFrame(Vector* point, Quaternion* direction, float time, ANIM_FUNCTION animFunc = ANIM_LINEAR); |
---|
53 | void addKeyFrame(KeyFrame3D* frame); |
---|
54 | |
---|
55 | virtual void tick(float timePassed); |
---|
56 | |
---|
57 | // animation functions |
---|
58 | void setAnimFunc(ANIM_FUNCTION animFunc); |
---|
59 | |
---|
60 | float constant(float timePassed) const; |
---|
61 | float linear(float timePassed) const; |
---|
62 | float sine(float timePassed) const; |
---|
63 | float cosine(float timePassed) const; |
---|
64 | float exp(float timePassed) const; |
---|
65 | float negExp(float timePassed) const; |
---|
66 | float quadratic(float timePassed) const; |
---|
67 | float random(float timePassed) const; |
---|
68 | // ANIM_FUNCTION animFunc; |
---|
69 | KeyFrame3D* currentKeyFrame; |
---|
70 | KeyFrame3D* nextKeyFrame; |
---|
71 | tList<KeyFrame3D>* keyFrameList; |
---|
72 | |
---|
73 | // private |
---|
74 | WorldEntity* object; |
---|
75 | Vector* lastPosition; |
---|
76 | Vector* tmpVect; |
---|
77 | float deltaT; |
---|
78 | float localTime; |
---|
79 | |
---|
80 | tList<KeyFrame3D>* frames; |
---|
81 | KeyFrame3D* currentFrame; |
---|
82 | KeyFrame3D* lastFrame; |
---|
83 | |
---|
84 | bool bRunning; |
---|
85 | |
---|
86 | animationMode animMode; |
---|
87 | movementMode movMode; |
---|
88 | }; |
---|
89 | |
---|
90 | //! Animation Class |
---|
91 | /** |
---|
92 | Helps you making some small animation |
---|
93 | */ |
---|
94 | class SimpleAnimation : public BaseObject { |
---|
95 | public: |
---|
96 | static SimpleAnimation* getInstance(); |
---|
97 | virtual ~SimpleAnimation(); |
---|
98 | |
---|
99 | void animatorBegin(); |
---|
100 | void animatorEnd(); |
---|
101 | void selectObject(WorldEntity* entity); |
---|
102 | void addKeyFrame(Vector* point, Quaternion* direction, float time); |
---|
103 | void addKeyFrame(Vector* point, Quaternion* direction, float time, movementMode mode); |
---|
104 | void addKeyFrame(KeyFrame3D* frame); |
---|
105 | void setAnimationMode(animationMode mode); |
---|
106 | void reset(); |
---|
107 | |
---|
108 | |
---|
109 | void start(); |
---|
110 | void stop(); |
---|
111 | void restart(); |
---|
112 | void pause(); |
---|
113 | void resume(); |
---|
114 | |
---|
115 | void tick(float time); |
---|
116 | |
---|
117 | private: |
---|
118 | SimpleAnimation(); |
---|
119 | |
---|
120 | static SimpleAnimation* singletonRef; |
---|
121 | bool bDescriptive; //<! is true, when AnimatorBegin() was executed but no AnimatorEnd() yet: in describtive mode: pass commands |
---|
122 | bool bRunning; //<! is set, when the animation is running |
---|
123 | tList<KeyFrame3D>* frames; //<! where keyframes are stored in |
---|
124 | tList<Animation3D>* animators; //<! a list of animation's |
---|
125 | KeyFrame3D* currentFrame; //<! the frame that is been played now |
---|
126 | KeyFrame3D* lastFrame; |
---|
127 | Vector* lastPosition; |
---|
128 | movementMode mode; //<! this is an enum of the mode, how the speed is distributed |
---|
129 | float localTime; |
---|
130 | PNode* parent; |
---|
131 | |
---|
132 | Vector* tmpVect; //<! this is the temporary vector save place - |
---|
133 | WorldEntity* workingObject; //<! this is a pointer to the current working object that has been selected via selectObject() |
---|
134 | Animation3D* workingAnimator; //<! the animator with which you are currently working |
---|
135 | float deltaT; //<! this is a time constant for the movement |
---|
136 | |
---|
137 | Animation3D* getAnimationFromWorldEntity(WorldEntity* entity); |
---|
138 | |
---|
139 | }; |
---|
140 | |
---|
141 | #endif /* _SIMPLE_ANIMATION_H */ |
---|