[3573] | 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 | |
---|
| 16 | |
---|
[3746] | 17 | class Vector; |
---|
| 18 | class Quaternion; |
---|
| 19 | class WorldEntity; |
---|
| 20 | class PNode; |
---|
[3573] | 21 | |
---|
[3746] | 22 | typedef enum movementMode{LINEAR=0, EXP, NEG_EXP, SIN, COS, QUADRATIC}; |
---|
| 23 | typedef enum animationMode{SINGLE=0, LOOP}; |
---|
| 24 | #define DEFAULT_ANIMATION_MODE LINEAR |
---|
[3573] | 25 | |
---|
[3746] | 26 | |
---|
| 27 | //! KeyFrame Struct |
---|
[3573] | 28 | /** |
---|
[3746] | 29 | This represents one point with direction of the animation |
---|
[3573] | 30 | */ |
---|
[3746] | 31 | typedef struct KeyFrame { |
---|
| 32 | Vector* position; |
---|
| 33 | Quaternion* direction; |
---|
| 34 | WorldEntity* object; |
---|
[3573] | 35 | float time; |
---|
| 36 | movementMode mode; |
---|
| 37 | }; |
---|
| 38 | |
---|
[3746] | 39 | //! Animation Struct |
---|
| 40 | /** |
---|
| 41 | This represents an animation for a object |
---|
| 42 | */ |
---|
| 43 | typedef struct Animation { |
---|
| 44 | WorldEntity* object; |
---|
| 45 | KeyFrame* currentFrame; |
---|
| 46 | KeyFrame* lastFrame; |
---|
| 47 | Vector* lastPosition; |
---|
| 48 | Vector* tmpVect; |
---|
| 49 | tList<KeyFrame>* frames; |
---|
| 50 | animationMode animMode; |
---|
| 51 | movementMode movMode; |
---|
| 52 | bool bRunning; |
---|
| 53 | float deltaT; |
---|
| 54 | }; |
---|
[3573] | 55 | |
---|
| 56 | //! Animation Class |
---|
| 57 | /** |
---|
| 58 | Helps you making some small animation |
---|
| 59 | */ |
---|
| 60 | class SimpleAnimation : public BaseObject { |
---|
| 61 | |
---|
| 62 | public: |
---|
[3746] | 63 | static SimpleAnimation* getInstance(); |
---|
[3573] | 64 | |
---|
[3746] | 65 | void animatorBegin(); |
---|
| 66 | void animatorEnd(); |
---|
| 67 | void selectObject(WorldEntity* entity); |
---|
| 68 | void addKeyFrame(Vector* point, Quaternion* direction, float time); |
---|
| 69 | void addKeyFrame(Vector* point, Quaternion* direction, float time, movementMode mode); |
---|
[3573] | 70 | void addKeyFrame(KeyFrame* frame); |
---|
| 71 | void reset(); |
---|
| 72 | |
---|
[3746] | 73 | |
---|
[3573] | 74 | void start(); |
---|
| 75 | void stop(); |
---|
| 76 | void restart(); |
---|
| 77 | void pause(); |
---|
| 78 | void resume(); |
---|
| 79 | |
---|
| 80 | void tick(float time); |
---|
| 81 | |
---|
| 82 | private: |
---|
[3746] | 83 | SimpleAnimation(); |
---|
| 84 | virtual ~SimpleAnimation(); |
---|
| 85 | |
---|
| 86 | static SimpleAnimation* singletonRef; |
---|
| 87 | bool bDescriptive; //<! is true, when AnimatorBegin() was executed but no AnimatorEnd() yet: in describtive mode: pass commands |
---|
| 88 | bool bRunning; //<! is set, when the animation is running |
---|
| 89 | tList<KeyFrame>* frames; //<! where keyframes are stored in |
---|
| 90 | tList<Animation>* animators; //<! a list of animation's |
---|
| 91 | KeyFrame* currentFrame; //<! the frame that is been played now |
---|
| 92 | KeyFrame* lastFrame; |
---|
| 93 | Vector* lastPosition; |
---|
| 94 | movementMode mode; //<! this is an enum of the mode, how the speed is distributed |
---|
[3573] | 95 | float localTime; |
---|
| 96 | PNode* parent; |
---|
| 97 | |
---|
[3746] | 98 | Vector* tmpVect; //<! this is the temporary vector save place - |
---|
| 99 | WorldEntity* workingObject; //<! this is a pointer to the current working object that has been selected via selectObject() |
---|
| 100 | Animation* workingAnimator; //<! the animator with which you are currently working |
---|
| 101 | float deltaT; //<! this is a time constant for the movement |
---|
[3573] | 102 | |
---|
[3746] | 103 | Animation* getAnimationFromWorldEntity(WorldEntity* entity); |
---|
| 104 | |
---|
[3573] | 105 | }; |
---|
| 106 | |
---|
| 107 | #endif /* _SIMPLE_ANIMATION_H */ |
---|