Changeset 3795 in orxonox.OLD for orxonox/trunk/src
- Timestamp:
- Apr 13, 2005, 4:32:53 PM (20 years ago)
- Location:
- orxonox/trunk/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/animation.cc
r3794 r3795 21 21 22 22 Anim::Anim(void) 23 { 24 // create a new List 25 this->keyFrameList = new tList<AnimKeyFrame>(); 26 23 { 27 24 // initialize a beginning KeyFrame, that will be deleted afterwards 28 25 this->bHasKeys = false; 29 AnimKeyFrame* tmpKeyFrame = new AnimKeyFrame;30 tmpKeyFrame->value = 0.0;31 tmpKeyFrame->duration = 1.0;32 keyFrameList->add(tmpKeyFrame);33 26 34 27 // setting default values 35 28 this->localTime = 0.0; 36 29 this->bRunning = true; 37 this->animFunc = &Anim::linear;38 this->currentKeyFrame = tmpKeyFrame;39 this->nextKeyFrame = tmpKeyFrame;40 30 } 41 31 … … 43 33 Anim::~Anim(void) 44 34 { 45 // delete all the KeyFrames46 tIterator<AnimKeyFrame>* itKF = keyFrameList->getIterator();47 AnimKeyFrame* enumKF = itKF->nextElement();48 while (enumKF)49 {50 delete enumKF;51 enumKF = itKF->nextElement();52 }53 delete itKF;54 delete this->keyFrameList;55 }56 57 tList<Anim>* Anim::animatorList = NULL;58 59 60 void Anim::addKeyFrame(float value, float duration, ANIM_FUNCTION animFunc)61 {62 // some small check63 if (duration <= 0.0)64 duration = 1.0;65 66 67 AnimKeyFrame* tmpKeyFrame;68 69 if (bHasKeys)70 {71 tmpKeyFrame = new AnimKeyFrame;72 if (this->currentKeyFrame == this->nextKeyFrame)73 this->nextKeyFrame = tmpKeyFrame;74 this->keyFrameList->add(tmpKeyFrame);75 76 }77 else78 {79 tmpKeyFrame = this->keyFrameList->firstElement();80 bHasKeys = true;81 }82 tmpKeyFrame->value = value;83 tmpKeyFrame->duration = duration;84 tmpKeyFrame->animFunc = animFunc;85 86 35 } 87 36 … … 90 39 this->postInfinity = postInfinity; 91 40 } 92 93 void Anim::setAnimFunc(ANIM_FUNCTION animFunc)94 {95 switch (animFunc)96 {97 default:98 case ANIM_CONSTANT:99 this->animFunc = &Anim::constant;100 break;101 case ANIM_LINEAR:102 this->animFunc = &Anim::linear;103 break;104 case ANIM_RANDOM:105 this->animFunc = &Anim::random;106 break;107 case ANIM_SINE:108 this->animFunc = &Anim::sine;109 break;110 }111 }112 113 114 // animation functions115 float Anim::random(float timePassed) const116 {117 return (float)rand()/(float)RAND_MAX;118 }119 120 float Anim::constant(float timePassed) const121 {122 return this->currentKeyFrame->value;123 }124 125 float Anim::linear(float timePassed) const126 {127 return this->nextKeyFrame->value - (this->nextKeyFrame->value - this->currentKeyFrame->value)128 * (timePassed / this->currentKeyFrame->duration);129 // PRINTF(0)("value is %f, %p %p\n", val, this->currentKeyFrame, this->nextKeyFrame);130 // return val;131 }132 133 float Anim::sine(float timePassed) const134 {135 136 } -
orxonox/trunk/src/animation.h
r3794 r3795 27 27 #define _ANIMATION_H 28 28 29 29 #include "list.h" 30 30 // FORWARD DEFINITION 31 template<class T> class tList;32 31 33 32 typedef enum ANIM_FUNCTION {ANIM_CONSTANT, … … 55 54 void setInfinity(ANIM_INFINITY postInfinity = ANIM_INF_CONSTANT); 56 55 57 void addKeyFrame(float value, float duration, ANIM_FUNCTION animFunc = ANIM_LINEAR);58 void setAnimFunc(ANIM_FUNCTION animFunc);59 60 56 void play(); // equals resume(); 61 57 void stop(); 62 58 void pause(); 63 59 void replay(); 60 // virtual void rewind(); 64 61 65 62 virtual void tick(float time) = 0; 66 63 64 /* implement in subclasses: 65 * 66 * De-/Constructor 67 * Animation Functions 68 * virtual tick 69 * List of keyFrames 70 * currentKeyFrame/nextKeyFrame 71 * virtual rewind, to go to the first Keyframe. (other functions will call this one) 72 */ 67 73 protected: 68 74 Anim(void); 69 75 70 static tList<Anim>* animatorList; 76 // variables 77 78 float localTime; 79 ANIM_INFINITY postInfinity; 80 81 bool bHasKeys; 82 bool bRunning; 83 }; 84 85 86 //! A Class to handle some animation for single floated values. 87 template<class T> class tAnim : public Anim 88 { 89 public: 90 tAnim(T* object = NULL, void (T::*funcToAnim)(float) = NULL); 91 virtual ~tAnim(); 92 93 void setFuncToAnim(T* object, void (T::*funcToAnim)(float)); 94 void addKeyFrame(float value, float duration, ANIM_FUNCTION animFunc = ANIM_LINEAR); 95 71 96 72 97 // animation functions 98 void setAnimFunc(ANIM_FUNCTION animFunc); 99 73 100 float random(float timePassed) const; 74 101 float constant(float timePassed) const; 75 102 float linear(float timePassed) const; 76 103 float sine(float timePassed) const; 77 78 79 // variables80 104 // ANIM_FUNCTION animFunc; 81 float (Anim::*animFunc)(float) const; 82 83 ANIM_INFINITY postInfinity; 84 85 bool bHasKeys; 86 bool bRunning; 87 88 float localTime; 105 float (tAnim<T>::*animFunc)(float) const; 89 106 AnimKeyFrame* currentKeyFrame; 90 107 AnimKeyFrame* nextKeyFrame; 91 108 tList<AnimKeyFrame>* keyFrameList; 92 }; 93 94 95 //! A Class to handle some animation for single floated values. 96 template<class T> class tAnim : public Anim 97 { 98 public: 99 tAnim(T* object = NULL, void (T::*funcToAnim)(float) = NULL); 100 virtual ~tAnim(); 101 102 void setFuncToAnim(T* object, void (T::*funcToAnim)(float)); 109 110 111 103 112 104 113 virtual void tick(float time); … … 118 127 tAnim<T>::tAnim (T* object, void (T::*funcToAnim)(float)) 119 128 { 129 // create a new List 130 this->keyFrameList = new tList<AnimKeyFrame>(); 131 AnimKeyFrame* tmpKeyFrame = new AnimKeyFrame; 132 tmpKeyFrame->value = 0.0; 133 tmpKeyFrame->duration = 1.0; 134 keyFrameList->add(tmpKeyFrame); 135 136 this->currentKeyFrame = tmpKeyFrame; 137 this->nextKeyFrame = tmpKeyFrame; 138 139 this->animFunc = &tAnim<T>::linear; 140 120 141 this->setFuncToAnim(object, funcToAnim); 121 142 } … … 129 150 tAnim<T>::~tAnim () 130 151 { 131 // delete what has to be deleted here 152 // delete all the KeyFrames 153 tIterator<AnimKeyFrame>* itKF = keyFrameList->getIterator(); 154 AnimKeyFrame* enumKF = itKF->nextElement(); 155 while (enumKF) 156 { 157 delete enumKF; 158 enumKF = itKF->nextElement(); 159 } 160 delete itKF; 161 delete this->keyFrameList; 162 132 163 } 133 164 … … 138 169 this->object = object; 139 170 this->funcToAnim = funcToAnim; 171 } 172 173 template<class T> 174 void tAnim<T>::addKeyFrame(float value, float duration, ANIM_FUNCTION animFunc) 175 { 176 // some small check 177 if (duration <= 0.0) 178 duration = 1.0; 179 180 181 AnimKeyFrame* tmpKeyFrame; 182 183 if (bHasKeys) 184 { 185 tmpKeyFrame = new AnimKeyFrame; 186 if (this->currentKeyFrame == this->nextKeyFrame) 187 this->nextKeyFrame = tmpKeyFrame; 188 this->keyFrameList->add(tmpKeyFrame); 189 190 } 191 else 192 { 193 tmpKeyFrame = this->keyFrameList->firstElement(); 194 bHasKeys = true; 195 } 196 tmpKeyFrame->value = value; 197 tmpKeyFrame->duration = duration; 198 tmpKeyFrame->animFunc = animFunc; 199 140 200 } 141 201 … … 170 230 } 171 231 232 233 template<class T> 234 void tAnim<T>::setAnimFunc(ANIM_FUNCTION animFunc) 235 { 236 switch (animFunc) 237 { 238 default: 239 case ANIM_CONSTANT: 240 this->animFunc = &tAnim<T>::constant; 241 break; 242 case ANIM_LINEAR: 243 this->animFunc = &tAnim<T>::linear; 244 break; 245 case ANIM_RANDOM: 246 this->animFunc = &tAnim<T>::random; 247 break; 248 case ANIM_SINE: 249 this->animFunc = &tAnim<T>::sine; 250 break; 251 } 252 } 253 254 255 // animation functions 256 template<class T> 257 float tAnim<T>::random(float timePassed) const 258 { 259 return (float)rand()/(float)RAND_MAX; 260 } 261 262 template<class T> 263 float tAnim<T>::constant(float timePassed) const 264 { 265 return this->currentKeyFrame->value; 266 } 267 268 template<class T> 269 float tAnim<T>::linear(float timePassed) const 270 { 271 return this->nextKeyFrame->value - (this->nextKeyFrame->value - this->currentKeyFrame->value) 272 * (timePassed / this->currentKeyFrame->duration); 273 // PRINTF(0)("value is %f, %p %p\n", val, this->currentKeyFrame, this->nextKeyFrame); 274 // return val; 275 } 276 277 template<class T> 278 float tAnim<T>::sine(float timePassed) const 279 { 280 281 } 282 172 283 #endif /* _ANIMATION_H */ -
orxonox/trunk/src/story_entities/world.h
r3794 r3795 24 24 class GarbageCollector; 25 25 class SimpleAnimation; 26 classAnim;26 template<class T> class tAnim; 27 27 class Text; 28 28 … … 99 99 GLMenuImageScreen* glmis; //!< The Level-Loader Display 100 100 101 Anim* testAnim;101 tAnim<Text>* testAnim; 102 102 Text* testText; //!< A text to Test the TextEngine; 103 103
Note: See TracChangeset
for help on using the changeset viewer.