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 | |
---|
22 | #ifndef _ANIMATION_H |
---|
23 | #define _ANIMATION_H |
---|
24 | |
---|
25 | |
---|
26 | // FORWARD DEFINITION |
---|
27 | template<class T> class tList; |
---|
28 | |
---|
29 | enum ANIM_FUNCTION {ANIM_LINEAR, ANIM_SINE }; |
---|
30 | enum ANIM_INFINITY {ANIM_INF_CONSTANT, ANIM_INF_LINEAR, ANIM_INF_PINGPONG, ANIM_INF_REWIND};//, ANIM_DELETE} |
---|
31 | |
---|
32 | class Anim |
---|
33 | { |
---|
34 | protected: |
---|
35 | Anim(); |
---|
36 | |
---|
37 | static tList<Anim>* animatorList; |
---|
38 | |
---|
39 | virtual void tick(float time) = 0; |
---|
40 | }; |
---|
41 | |
---|
42 | |
---|
43 | //! A Class to handle some animation for single floated values. |
---|
44 | template<class T> class Animation : public Anim |
---|
45 | { |
---|
46 | public: |
---|
47 | Animation(); |
---|
48 | virtual ~Animation(); |
---|
49 | |
---|
50 | void setFuncToAnim(T* object, void (T::*funcToAnim)(float)); |
---|
51 | void setAnimFunc(ANIM_FUNCTION animFunc); |
---|
52 | void setValue(float value); |
---|
53 | |
---|
54 | virtual void tick(float time); |
---|
55 | |
---|
56 | private: |
---|
57 | void (T::*funcToAnim)(float); |
---|
58 | ANIM_FUNCTION animFunc; |
---|
59 | float value; |
---|
60 | T* object; |
---|
61 | }; |
---|
62 | |
---|
63 | |
---|
64 | |
---|
65 | /** |
---|
66 | \brief standard constructor |
---|
67 | |
---|
68 | */ |
---|
69 | template<class T> |
---|
70 | Animation<T>::Animation () |
---|
71 | { |
---|
72 | this->value = 0.0; |
---|
73 | } |
---|
74 | |
---|
75 | |
---|
76 | /** |
---|
77 | \brief standard deconstructor |
---|
78 | |
---|
79 | */ |
---|
80 | template<class T> |
---|
81 | Animation<T>::~Animation () |
---|
82 | { |
---|
83 | // delete what has to be deleted here |
---|
84 | } |
---|
85 | |
---|
86 | |
---|
87 | template<class T> |
---|
88 | void Animation<T>::setFuncToAnim(T* object, void (T::*funcToAnim)(float)) |
---|
89 | { |
---|
90 | this->object = object; |
---|
91 | this->funcToAnim = funcToAnim; |
---|
92 | } |
---|
93 | |
---|
94 | template<class T> |
---|
95 | void Animation<T>::setValue(float value) |
---|
96 | { |
---|
97 | this->value = value; |
---|
98 | (object->*(funcToAnim))(value); |
---|
99 | } |
---|
100 | |
---|
101 | template<class T> |
---|
102 | void Animation<T>::tick(float time) |
---|
103 | { |
---|
104 | setValue(value - time/1000); |
---|
105 | if (value < 0) |
---|
106 | setValue (1.0); |
---|
107 | } |
---|
108 | |
---|
109 | #endif /* _ANIMATION_H */ |
---|