Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: animation: more adaptions to the new Framework

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 PNode;
21
22typedef enum movementMode{LINEAR=0, EXP, NEG_EXP, SIN, COS, QUADRATIC};
23typedef enum animationMode{SINGLE=0, LOOP};
24#define DEFAULT_ANIMATION_MODE LINEAR
25
26
27//! KeyFrame Struct
28/**
29   This represents one point with direction of the animation
30*/
31typedef struct KeyFrame3D {
32  Vector* position;
33  Quaternion* direction;
34  PNode* object;
35  float time;
36  movementMode mode;
37};
38
39//! Animation Struct
40/**
41   This represents an animation for a object
42*/
43class Animation3D : public Animation
44{
45 public:
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
59 private:
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  PNode* 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(PNode* 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  PNode* 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* getAnimationFromPNode(PNode* entity);
139
140};
141
142#endif /* _SIMPLE_ANIMATION_H */
Note: See TracBrowser for help on using the repository browser.