- Timestamp:
- Apr 13, 2005, 12:24:05 AM (20 years ago)
- Location:
- orxonox/branches/textEngine/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/textEngine/src/animation.cc
r3782 r3784 17 17 #include "animation.h" 18 18 #include "debug.h" 19 #include "list.h" 19 20 20 21 21 22 Anim::Anim(void) 22 23 { 24 // create a new List 25 this->keyFrameList = new tList<AnimKeyFrame>(); 26 27 // initialize a beginning KeyFrame, that will be deleted afterwards 28 this->bHasKeys = false; 29 30 31 this->animFunc = &Anim::random; 23 32 } 24 33 25 34 35 Anim::~Anim(void) 36 { 37 // delete all the KeyFrames 38 tIterator<AnimKeyFrame>* itKF = keyFrameList->getIterator(); 39 AnimKeyFrame* enumKF = itKF->nextElement(); 40 while (enumKF) 41 { 42 delete enumKF; 43 enumKF = itKF->nextElement(); 44 } 45 delete itKF; 46 delete this->keyFrameList; 47 } 48 26 49 tList<Anim>* Anim::animatorList = NULL; 50 51 52 void Anim::addKeyFrame(float value, float duration, ANIM_FUNCTION animFunc) 53 { 54 if (!bHasKeys) 55 { 56 this->keyFrameList->remove(this->keyFrameList->firstElement()); 57 bHasKeys = true; 58 } 59 AnimKeyFrame* tmpKeyFrame = new AnimKeyFrame; 60 tmpKeyFrame->value = value; 61 tmpKeyFrame->duration = duration; 62 tmpKeyFrame->animFunc = animFunc; 63 64 this->keyFrameList->add(tmpKeyFrame); 65 } 66 67 void Anim::setInfinity(ANIM_INFINITY preInfinity, ANIM_INFINITY postInfinity) 68 { 69 this->preInfinity = preInfinity; 70 this->postInfinity = postInfinity; 71 } 72 73 void Anim::setAnimFunc(ANIM_FUNCTION animFunc) 74 { 75 switch (animFunc) 76 { 77 default: 78 case ANIM_CONSTANT: 79 this->animFunc = &Anim::constant; 80 break; 81 case ANIM_LINEAR: 82 this->animFunc = &Anim::linear; 83 break; 84 case ANIM_RANDOM: 85 this->animFunc = &Anim::random; 86 break; 87 case ANIM_SINE: 88 this->animFunc = &Anim::sine; 89 break; 90 91 } 92 } 93 94 95 // animation functions 96 float Anim::random(float time) 97 { 98 return (float)rand()/(float)RAND_MAX; 99 } 100 101 float Anim::constant(float time) 102 { 103 104 } 105 106 float Anim::linear(float time) 107 { 108 109 } 110 111 float Anim::sine(float time) 112 { 113 114 } -
orxonox/branches/textEngine/src/animation.h
r3783 r3784 18 18 \file animation.h 19 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. 20 24 */ 21 25 … … 27 31 template<class T> class tList; 28 32 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} 33 typedef enum ANIM_FUNCTION {ANIM_CONSTANT, 34 ANIM_LINEAR, 35 ANIM_SINE, 36 ANIM_RANDOM}; 37 typedef enum ANIM_INFINITY {ANIM_INF_CONSTANT, 38 ANIM_INF_LINEAR, 39 ANIM_INF_PINGPONG, 40 ANIM_INF_REWIND};//, ANIM_DELETE} 41 42 struct AnimKeyFrame 43 { 44 float duration; 45 float value; 46 ANIM_FUNCTION animFunc; 47 }; 31 48 32 49 class Anim 33 50 { 34 51 protected: 35 Anim(); 52 Anim(void); 53 virtual ~Anim(void); 36 54 37 55 static tList<Anim>* animatorList; 38 56 39 57 virtual void tick(float time) = 0; 58 59 void addKeyFrame(float value, float duration, ANIM_FUNCTION animFunc = ANIM_LINEAR); 60 void setInfinity(ANIM_INFINITY preInfinity = ANIM_INF_CONSTANT, 61 ANIM_INFINITY postInfinity = ANIM_INF_CONSTANT); 62 void setAnimFunc(ANIM_FUNCTION animFunc); 63 64 65 // animation functions 66 float random(float time); 67 float constant(float time); 68 float linear(float time); 69 float sine(float time); 70 71 72 // variables 73 // ANIM_FUNCTION animFunc; 74 float (Anim::*animFunc)(float); 75 ANIM_INFINITY preInfinity; 76 ANIM_INFINITY postInfinity; 77 78 bool bHasKeys; 79 tList<AnimKeyFrame>* keyFrameList; 40 80 }; 41 81 … … 45 85 { 46 86 public: 47 Animation( );87 Animation(T* object = NULL, void (T::*funcToAnim)(float) = NULL); 48 88 virtual ~Animation(); 49 89 50 90 void setFuncToAnim(T* object, void (T::*funcToAnim)(float)); 51 void setAnimFunc(ANIM_FUNCTION animFunc);52 void setValue(float value);53 91 54 92 virtual void tick(float time); 55 93 56 94 private: 95 T* object; 57 96 void (T::*funcToAnim)(float); 58 ANIM_FUNCTION animFunc;59 float value;60 T* object;61 97 }; 62 98 … … 68 104 */ 69 105 template<class T> 70 Animation<T>::Animation ( )106 Animation<T>::Animation (T* object, void (T::*funcToAnim)(float)) 71 107 { 72 this->value = 0.0;108 this->setFuncToAnim(object, funcToAnim); 73 109 } 74 110 … … 92 128 } 93 129 94 template<class T>95 void Animation<T>::setValue(float value)96 {97 this->value = value;98 (object->*(funcToAnim))(value);99 }100 130 101 131 template<class T> 102 132 void Animation<T>::tick(float time) 103 133 { 104 setValue(value - time/1000); 105 if (value < 0) 106 setValue (1.0); 134 (this->object->*(funcToAnim))((this->*animFunc)(time)); 107 135 } 108 136 -
orxonox/branches/textEngine/src/story_entities/world.cc
r3781 r3784 360 360 361 361 362 tmpAnim = new Animation<Text>( );363 364 tmpAnim->setFuncToAnim(testText, &Text::setBlending);362 tmpAnim = new Animation<Text>(testText, &Text::setBlending); 363 364 // tmpAnim->setFuncToAnim(testText, &Text::setBlending); 365 365 break; 366 366 }
Note: See TracChangeset
for help on using the changeset viewer.