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