Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/simple_animation.h @ 3850

Last change on this file since 3850 was 3850, checked in by bensch, 19 years ago

orxonox/trunk: added some functions (for function pointers) to the Animation3D class

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