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