Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/textEngine/src/animation.h @ 3785

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

orxonox/branches/textEngine: linear works
example shows an indicator of how fast the framerate is.

File size: 2.8 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: Benjamin Grauer
13   co-programmer: ...
14*/
15
16
17/*!
18    \file animation.h
19    A Set of functions to animate some floats inside of an Object
20
21    We apologize, that most part of the Function-Definitions are located
22    inside this h-file, but this must be like this because it is a template
23    function.
24*/
25
26#ifndef _ANIMATION_H
27#define _ANIMATION_H
28
29
30// FORWARD DEFINITION
31template<class T> class tList;
32
33typedef enum ANIM_FUNCTION {ANIM_CONSTANT,
34                            ANIM_LINEAR,
35                            ANIM_SINE,
36                            ANIM_RANDOM};
37typedef enum ANIM_INFINITY {ANIM_INF_CONSTANT,
38                            ANIM_INF_LINEAR,
39                            ANIM_INF_PINGPONG,
40                            ANIM_INF_REWIND};//, ANIM_DELETE}
41
42struct AnimKeyFrame
43{
44  float duration;
45  float value;
46  ANIM_FUNCTION animFunc;
47};
48
49class Anim
50{
51 public:
52  void addKeyFrame(float value, float duration, ANIM_FUNCTION animFunc = ANIM_LINEAR);
53  void setInfinity(ANIM_INFINITY preInfinity = ANIM_INF_CONSTANT,
54                   ANIM_INFINITY postInfinity = ANIM_INF_CONSTANT);
55  void setAnimFunc(ANIM_FUNCTION animFunc);
56
57 protected:
58  Anim(void);
59  virtual ~Anim(void);
60
61  static tList<Anim>* animatorList;
62
63  virtual void tick(float time) = 0;
64
65
66
67  // animation functions
68  float random(float time) const;
69  float constant(float time) const;
70  float linear(float time) const;
71  float sine(float time) const;
72
73
74  // variables
75  //  ANIM_FUNCTION animFunc;
76  float (Anim::*animFunc)(float) const;
77  ANIM_INFINITY preInfinity;
78  ANIM_INFINITY postInfinity;
79
80  bool bHasKeys;
81
82  AnimKeyFrame* currentKeyFrame;
83  AnimKeyFrame* nextKeyFrame;
84  tList<AnimKeyFrame>* keyFrameList;
85};
86
87
88//! A Class to handle some animation for single floated values.
89template<class T> class Animation : public Anim
90{
91 public:
92  Animation(T* object = NULL, void (T::*funcToAnim)(float) = NULL);
93  virtual ~Animation();
94
95  void setFuncToAnim(T* object, void (T::*funcToAnim)(float));
96
97  virtual void tick(float time);
98
99 private:
100  T* object;
101  void (T::*funcToAnim)(float);
102};
103
104
105
106/**
107   \brief standard constructor
108
109*/
110template<class T>
111Animation<T>::Animation (T* object, void (T::*funcToAnim)(float)) 
112{
113  this->setFuncToAnim(object, funcToAnim);
114}
115
116
117/**
118   \brief standard deconstructor
119
120*/
121template<class T>
122Animation<T>::~Animation () 
123{
124  // delete what has to be deleted here
125}
126
127
128template<class T>
129void Animation<T>::setFuncToAnim(T* object, void (T::*funcToAnim)(float))
130{
131  this->object = object;
132  this->funcToAnim = funcToAnim;
133}
134
135
136template<class T>
137void Animation<T>::tick(float time)
138{
139  (this->object->*(funcToAnim))((this->*animFunc)(time));
140}
141
142#endif /* _ANIMATION_H */
Note: See TracBrowser for help on using the repository browser.