[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 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 | */ |
---|
[3848] | 32 | typedef struct KeyFrame3D { |
---|
[3726] | 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 | */ |
---|
[3848] | 44 | class Animation3D : public Animation |
---|
[3847] | 45 | { |
---|
| 46 | public: |
---|
[3848] | 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 |
---|
[3738] | 74 | WorldEntity* object; |
---|
| 75 | Vector* lastPosition; |
---|
| 76 | Vector* tmpVect; |
---|
[3750] | 77 | float deltaT; |
---|
| 78 | float localTime; |
---|
| 79 | |
---|
[3848] | 80 | tList<KeyFrame3D>* frames; |
---|
| 81 | KeyFrame3D* currentFrame; |
---|
| 82 | KeyFrame3D* lastFrame; |
---|
[3750] | 83 | |
---|
| 84 | bool bRunning; |
---|
| 85 | |
---|
[3738] | 86 | animationMode animMode; |
---|
| 87 | movementMode movMode; |
---|
| 88 | }; |
---|
[3573] | 89 | |
---|
| 90 | //! Animation Class |
---|
| 91 | /** |
---|
| 92 | Helps you making some small animation |
---|
| 93 | */ |
---|
| 94 | class SimpleAnimation : public BaseObject { |
---|
| 95 | public: |
---|
[3727] | 96 | static SimpleAnimation* getInstance(); |
---|
[3752] | 97 | virtual ~SimpleAnimation(); |
---|
[3573] | 98 | |
---|
[3729] | 99 | void animatorBegin(); |
---|
| 100 | void animatorEnd(); |
---|
[3727] | 101 | void selectObject(WorldEntity* entity); |
---|
[3729] | 102 | void addKeyFrame(Vector* point, Quaternion* direction, float time); |
---|
| 103 | void addKeyFrame(Vector* point, Quaternion* direction, float time, movementMode mode); |
---|
[3848] | 104 | void addKeyFrame(KeyFrame3D* frame); |
---|
[3752] | 105 | void setAnimationMode(animationMode mode); |
---|
[3573] | 106 | void reset(); |
---|
| 107 | |
---|
[3727] | 108 | |
---|
[3573] | 109 | void start(); |
---|
| 110 | void stop(); |
---|
| 111 | void restart(); |
---|
| 112 | void pause(); |
---|
| 113 | void resume(); |
---|
| 114 | |
---|
| 115 | void tick(float time); |
---|
| 116 | |
---|
| 117 | private: |
---|
[3727] | 118 | SimpleAnimation(); |
---|
| 119 | |
---|
| 120 | static SimpleAnimation* singletonRef; |
---|
[3733] | 121 | bool bDescriptive; //<! is true, when AnimatorBegin() was executed but no AnimatorEnd() yet: in describtive mode: pass commands |
---|
[3719] | 122 | bool bRunning; //<! is set, when the animation is running |
---|
[3848] | 123 | tList<KeyFrame3D>* frames; //<! where keyframes are stored in |
---|
[3847] | 124 | tList<Animation3D>* animators; //<! a list of animation's |
---|
[3848] | 125 | KeyFrame3D* currentFrame; //<! the frame that is been played now |
---|
| 126 | KeyFrame3D* lastFrame; |
---|
[3729] | 127 | Vector* lastPosition; |
---|
[3717] | 128 | movementMode mode; //<! this is an enum of the mode, how the speed is distributed |
---|
[3573] | 129 | float localTime; |
---|
| 130 | PNode* parent; |
---|
| 131 | |
---|
[3726] | 132 | Vector* tmpVect; //<! this is the temporary vector save place - |
---|
[3727] | 133 | WorldEntity* workingObject; //<! this is a pointer to the current working object that has been selected via selectObject() |
---|
[3847] | 134 | Animation3D* workingAnimator; //<! the animator with which you are currently working |
---|
[3733] | 135 | float deltaT; //<! this is a time constant for the movement |
---|
| 136 | |
---|
[3847] | 137 | Animation3D* getAnimationFromWorldEntity(WorldEntity* entity); |
---|
[3739] | 138 | |
---|
[3573] | 139 | }; |
---|
| 140 | |
---|
| 141 | #endif /* _SIMPLE_ANIMATION_H */ |
---|