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