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