Changeset 10618 in orxonox.OLD for trunk/src/util/animation/t_animation.h
- Timestamp:
- Apr 4, 2007, 12:13:53 PM (17 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:ignore
-
old new 16 16 OrxonoxPlayability.kdevses 17 17 OrxonoxPlayability.kdevelop.pcs 18 orxonox.backtrace 19 orxonox.kdevses 20 orxonox.kdevelop.pcs
-
- Property svn:ignore
-
trunk/src/util/animation/t_animation.h
r8315 r10618 1 1 /* 2 2 orxonox - the future of 3D-vertical-scrollers 3 3 4 4 Copyright (C) 2004 orx 5 5 6 6 This program is free software; you can redistribute it and/or modify 7 7 it under the terms of the GNU General Public License as published by 8 8 the Free Software Foundation; either version 2, or (at your option) 9 9 any later version. 10 10 11 11 ### File Specific: 12 12 main-programmer: Benjamin Grauer … … 37 37 template<class T> class tAnimation : public Animation 38 38 { 39 39 public: 40 40 tAnimation(T* object = NULL, void (T::*funcToAnim)(float) = NULL); 41 virtual ~tAnimation();42 41 43 42 void setFuncToAnim(T* object, void (T::*funcToAnim)(float)); … … 48 47 virtual void tick(float dt); 49 48 50 49 private: 51 50 // animation functions 52 51 void setAnimFunc(ANIM_FUNCTION animFunc); … … 61 60 62 61 62 private: 63 typedef std::list<KeyFrameF> KeyFrameList; 64 typedef typename KeyFrameList::iterator KeyFrameIterator; 65 63 66 // ANIM_FUNCTION animFunc 64 67 float (tAnimation<T>::*animFunc)(float) const; //!< A Function for the AnimationType 65 68 66 KeyFrame F*currentKeyFrame; //!< The current KeyFrame67 KeyFrame F*nextKeyFrame; //!< The KeyFrame we iterate to68 tList<KeyFrameF>*keyFrameList; //!< The KeyFrameList69 KeyFrameIterator currentKeyFrame; //!< The current KeyFrame 70 KeyFrameIterator nextKeyFrame; //!< The KeyFrame we iterate to 71 KeyFrameList keyFrameList; //!< The KeyFrameList 69 72 70 73 T* object; //!< The Object from which to Animate something … … 83 86 { 84 87 // create a new List 85 this->keyFrameList = new tList<KeyFrameF>(); 86 KeyFrameF* tmpKeyFrame = new KeyFrameF; 87 tmpKeyFrame->value = 0.0; 88 tmpKeyFrame->duration = 1.0; 89 keyFrameList->add(tmpKeyFrame); 90 91 this->currentKeyFrame = tmpKeyFrame; 92 this->nextKeyFrame = tmpKeyFrame; 88 KeyFrameF tmpKeyFrame; 89 tmpKeyFrame.value = 0.0; 90 tmpKeyFrame.duration = 1.0; 91 keyFrameList.push_back(tmpKeyFrame); 92 93 this->currentKeyFrame = keyFrameList.begin(); 94 this->nextKeyFrame = keyFrameList.begin(); 93 95 94 96 this->animFunc = &tAnimation<T>::linear; … … 99 101 100 102 /** 101 * standard deconstructor102 103 deletes all the Keyframes104 */105 template<class T>106 tAnimation<T>::~tAnimation ()107 {108 // delete all the KeyFrames109 tIterator<KeyFrameF>* itKF = keyFrameList->getIterator();110 KeyFrameF* enumKF = itKF->firstElement();111 while (enumKF)112 {113 delete enumKF;114 enumKF = itKF->nextElement();115 }116 delete itKF;117 delete this->keyFrameList;118 }119 120 /**121 103 * rewinds the Animation to the beginning (first KeyFrame and time == 0) 122 104 */ … … 124 106 void tAnimation<T>::rewind() 125 107 { 126 this->currentKeyFrame = keyFrameList ->firstElement();127 this->nextKeyFrame = keyFrameList->nextElement(keyFrameList->firstElement());108 this->currentKeyFrame = keyFrameList.begin(); 109 this->nextKeyFrame = ++keyFrameList.begin(); 128 110 this->localTime = 0.0; 129 this->setAnimFunc( this->currentKeyFrame->animFunc);111 this->setAnimFunc((*this->currentKeyFrame).animFunc); 130 112 } 131 113 … … 157 139 animFunc = ANIM_DEFAULT_FUNCTION; 158 140 159 KeyFrameF * tmpKeyFrame;141 KeyFrameF& tmpKeyFrame = keyFrameList.front(); 160 142 161 143 // when adding the first frame 162 144 if (this->keyFrameCount == 0) 163 { 164 tmpKeyFrame = this->keyFrameList->firstElement(); 165 this->setAnimFunc(animFunc); 166 } 145 { 146 this->setAnimFunc(animFunc); 147 } 167 148 else 168 169 tmpKeyFrame = new KeyFrameF;170 // when adding the second frame171 if (this->currentKeyFrame == this->nextKeyFrame)172 this->nextKeyFrame = tmpKeyFrame;173 this-> keyFrameList->add(tmpKeyFrame);174 175 176 tmpKeyFrame ->value = value;177 tmpKeyFrame ->duration = duration;178 tmpKeyFrame ->animFunc = animFunc;149 { 150 this->keyFrameList.push_back(KeyFrameF()); 151 tmpKeyFrame = keyFrameList.back(); 152 // when adding the second frame 153 if (this->currentKeyFrame == this->nextKeyFrame) 154 this->nextKeyFrame = --keyFrameList.end(); 155 } 156 157 tmpKeyFrame.value = value; 158 tmpKeyFrame.duration = duration; 159 tmpKeyFrame.animFunc = animFunc; 179 160 this->keyFrameCount++; 180 161 } … … 188 169 { 189 170 if (this->bRunning) 171 { 172 this->localTime += dt; 173 if (localTime >= this->currentKeyFrame->duration) 190 174 { 191 this->localTime += dt; 192 if (localTime >= this->currentKeyFrame->duration) 193 { 194 if (likely(this->keyFramesToPlay != 0)) 195 { 196 if (unlikely(this->keyFramesToPlay > 0)) 197 --this->keyFramesToPlay; 198 // switching to the next Key-Frame 199 this->localTime -= this->currentKeyFrame->duration; 200 201 this->currentKeyFrame = this->nextKeyFrame; 202 // checking, if we should still Play the animation 203 if (this->currentKeyFrame == this->keyFrameList->lastElement()) 204 this->handleInfinity(); 205 this->nextKeyFrame = this->keyFrameList->nextElement(this->currentKeyFrame); 206 207 //printf("%p from:%f to:%f\n", this->currentKeyFrame,this->currentKeyFrame->value, this->nextKeyFrame->value); 208 this->setAnimFunc(this->currentKeyFrame->animFunc); 209 } 210 else 211 this->pause(); 212 } 213 214 (this->object->*(funcToAnim))((this->*animFunc)(this->localTime)); 175 if (likely(this->keyFramesToPlay != 0)) 176 { 177 if (unlikely(this->keyFramesToPlay > 0)) 178 --this->keyFramesToPlay; 179 // switching to the next Key-Frame 180 this->localTime -= this->currentKeyFrame->duration; 181 182 this->currentKeyFrame = this->nextKeyFrame; 183 // checking, if we should still Play the animation 184 if (this->currentKeyFrame == --this->keyFrameList.end()) 185 this->handleInfinity(); 186 this->nextKeyFrame = this->currentKeyFrame; 187 this->nextKeyFrame++; 188 189 //printf("%p from:%f to:%f\n", this->currentKeyFrame,this->currentKeyFrame->value, this->nextKeyFrame->value); 190 this->setAnimFunc(this->currentKeyFrame->animFunc); 191 } 192 else 193 this->pause(); 215 194 } 195 196 (this->object->*(funcToAnim))((this->*animFunc)(this->localTime)); 197 } 216 198 } 217 199 … … 224 206 { 225 207 switch (animFunc) 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 208 { 209 default: 210 case ANIM_CONSTANT: 211 this->animFunc = &tAnimation<T>::constant; 212 break; 213 case ANIM_LINEAR: 214 this->animFunc = &tAnimation<T>::linear; 215 break; 216 case ANIM_SINE: 217 this->animFunc = &tAnimation<T>::sine; 218 break; 219 case ANIM_COSINE: 220 this->animFunc = &tAnimation<T>::cosine; 221 break; 222 case ANIM_EXP: 223 this->animFunc = &tAnimation<T>::exp; 224 break; 225 case ANIM_NEG_EXP: 226 this->animFunc = &tAnimation<T>::negExp; 227 expFactor = - 1.0 / this->currentKeyFrame->duration * logf(DELTA_X); 228 break; 229 case ANIM_QUADRATIC: 230 this->animFunc = &tAnimation<T>::quadratic; 231 break; 232 case ANIM_RANDOM: 233 this->animFunc = &tAnimation<T>::random; 234 break; 235 } 254 236 } 255 237 … … 274 256 { 275 257 return this->currentKeyFrame->value + (this->nextKeyFrame->value - this->currentKeyFrame->value) 276 * (timePassed / this->currentKeyFrame->duration);258 * (timePassed / this->currentKeyFrame->duration); 277 259 } 278 260 … … 286 268 if (timePassed * 2.0 < this->currentKeyFrame->duration) 287 269 return this->currentKeyFrame->value + (this->nextKeyFrame->value - this->currentKeyFrame->value) 288 * sin( M_PI * timePassed / this->currentKeyFrame->duration)/2;270 * sin( M_PI * timePassed / this->currentKeyFrame->duration)/2; 289 271 else 290 272 return this->nextKeyFrame->value - (this->nextKeyFrame->value - this->currentKeyFrame->value) 291 * sin( M_PI * (1.0 - timePassed / this->currentKeyFrame->duration))/2;273 * sin( M_PI * (1.0 - timePassed / this->currentKeyFrame->duration))/2; 292 274 /* 293 275 printf("::%f::::%f::\n",timePassed/this->currentKeyFrame->duration,retVal); … … 304 286 { 305 287 return ((this->nextKeyFrame->value + this->currentKeyFrame->value) + 306 (this->currentKeyFrame->value - this->nextKeyFrame->value) *307 cos( M_PI * timePassed / this->currentKeyFrame->duration))/2;288 (this->currentKeyFrame->value - this->nextKeyFrame->value) * 289 cos( M_PI * timePassed / this->currentKeyFrame->duration))/2; 308 290 } 309 291 … … 348 330 { 349 331 return this->currentKeyFrame->value + 350 (this->nextKeyFrame->value - this->currentKeyFrame->value) *351 (float)rand()/(float)RAND_MAX;332 (this->nextKeyFrame->value - this->currentKeyFrame->value) * 333 (float)rand()/(float)RAND_MAX; 352 334 } 353 335
Note: See TracChangeset
for help on using the changeset viewer.