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