Changeset 4597 in orxonox.OLD for orxonox/trunk/src/util/animation
- Timestamp:
- Jun 11, 2005, 12:55:48 AM (20 years ago)
- Location:
- orxonox/trunk/src/util/animation
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/util/animation/animation.cc
r3988 r4597 1 /* 1 /* 2 2 orxonox - the future of 3D-vertical-scrollers 3 3 … … 22 22 /** 23 23 \brief creates a new Animation 24 24 25 25 This also adds the Animation automatically to the AnimationPlayer's list 26 26 */ 27 27 Animation::Animation(void) 28 { 28 { 29 this->setClassID(CL_ANIMATION, "Animation"); 30 29 31 // initialize a beginning KeyFrame, that will be deleted afterwards 30 32 this->keyFrameCount = 0; … … 43 45 /** 44 46 \brief destructs the Animation 45 47 46 48 this also takes the animation out of the AnimationPlayer's list (if it is there) 47 49 */ … … 54 56 \brief tells the AnimationPlayer, that we do not wish to handle this animation 55 57 automatically. 56 58 57 59 This means that it will not be ticked, and not be deleted with the AnimationPlayer 58 60 */ -
orxonox/trunk/src/util/animation/animation.h
r4485 r4597 1 /*! 1 /*! 2 2 \file animation.h 3 3 A Subclass for all animations in orxonox … … 31 31 deprecated QUADRATIC 32 32 */ 33 typedef enum ANIM_FUNCTION {ANIM_CONSTANT, 34 ANIM_LINEAR, 35 ANIM_SINE, 36 ANIM_COSINE, 37 ANIM_EXP, 38 ANIM_NEG_EXP, 39 ANIM_QUADRATIC, 40 ANIM_RANDOM, 41 ANIM_NULL}; 33 typedef enum ANIM_FUNCTION 34 { 35 ANIM_CONSTANT, 36 ANIM_LINEAR, 37 ANIM_SINE, 38 ANIM_COSINE, 39 ANIM_EXP, 40 ANIM_NEG_EXP, 41 ANIM_QUADRATIC, 42 ANIM_RANDOM, 43 ANIM_NULL 44 }; 45 42 46 #define ANIM_DEFAULT_FUNCTION ANIM_LINEAR //!< A default function to choose from the above set 43 47 … … 49 53 ANIM_INF_DELETE deletes the animation. !! THIS IS DANGEROUS !! only do this with non-class variables 50 54 */ 51 typedef enum ANIM_INFINITY {ANIM_INF_CONSTANT, 52 ANIM_INF_REPLAY, 53 ANIM_INF_REWIND, 54 ANIM_INF_DELETE};//, ANIM_INF_LINEAR, ANIM_INF_PINGPONG; 55 typedef enum ANIM_INFINITY 56 { 57 ANIM_INF_CONSTANT, 58 ANIM_INF_REPLAY, 59 ANIM_INF_REWIND, 60 ANIM_INF_DELETE 61 }; //, ANIM_INF_LINEAR, ANIM_INF_PINGPONG}; 55 62 56 63 //! A Superclass for describing an animation (all animations will be derived from this one) 57 64 /** implement in subclasses: 58 * 65 * 59 66 * De-/Constructor 60 67 * Animation Functions … … 65 72 * virtual rewind, to go to the first Keyframe. (other functions will call this one) 66 73 */ 67 class Animation 74 class Animation : public BaseObject 68 75 { 69 76 public: -
orxonox/trunk/src/util/animation/animation3d.cc
r4485 r4597 51 51 /** 52 52 \brief standard deconstructor 53 53 54 54 deletes all the Keyframes 55 55 */ … … 89 89 */ 90 90 void Animation3D::addKeyFrame(Vector position, Quaternion direction, float duration, 91 91 ANIM_FUNCTION animFuncMov, ANIM_FUNCTION animFuncRot) 92 92 { 93 93 // some small check … … 101 101 102 102 KeyFrame3D* tmpKeyFrame; 103 103 104 104 // when adding the first frame 105 105 if (this->keyFrameCount == 0) … … 114 114 // when adding the second frame 115 115 if (this->currentKeyFrame == this->nextKeyFrame) 116 116 this->nextKeyFrame = tmpKeyFrame; 117 117 this->keyFrameList->add(tmpKeyFrame); 118 118 } … … 136 136 { 137 137 if (this->bRunning) 138 { 138 { 139 139 this->localTime += dt; 140 140 if (localTime >= this->currentKeyFrame->duration) 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 } 141 { 142 if (likely(this->keyFramesToPlay != 0)) 143 { 144 if (unlikely(this->keyFramesToPlay > 0)) 145 --this->keyFramesToPlay; 146 // switching to the next Key-Frame 147 this->localTime -= this->currentKeyFrame->duration; 148 this->currentKeyFrame = this->nextKeyFrame; 149 // checking, if we should still Play the animation 150 if (this->currentKeyFrame == this->keyFrameList->lastElement()) 151 this->handleInfinity(); 152 this->nextKeyFrame = this->keyFrameList->nextElement(this->currentKeyFrame); 153 this->setAnimFuncMov(this->currentKeyFrame->animFuncMov); 154 this->setAnimFuncRot(this->currentKeyFrame->animFuncRot); 155 } 156 else 157 this->pause(); 158 } 159 159 /* now animate it */ 160 160 (this->*animFuncMov)(this->localTime); … … 257 257 else 258 258 v = (this->nextKeyFrame->position - this->currentKeyFrame->position) * (2.0 + sin( M_PI * (- timePassed /this->currentKeyFrame->duration)) )/ 2.0; 259 259 260 260 this->object->shiftCoor(v - this->currentKeyFrame->lastPosition); 261 261 this->currentKeyFrame->lastPosition = v; … … 279 279 /* 280 280 this->object->setRelCoor( this->nextKeyFrame->position - 281 282 281 (this->nextKeyFrame->position - this->currentKeyFrame->position) * 282 (1.0 + cos( M_PI * timePassed / this->currentKeyFrame->duration))/2.0); 283 283 */ 284 284 } … … 309 309 /* 310 310 this->object->setRelCoor( this->currentKeyFrame->position + 311 (this->nextKeyFrame->position - this->currentKeyFrame->position) * 312 311 (this->nextKeyFrame->position - this->currentKeyFrame->position) * 312 (1.0 - expf(- timePassed * expFactorMov)) ); 313 313 */ 314 314 } … … 334 334 { 335 335 /* 336 this->object->setRelCoor(this->currentKeyFrame->position + 337 336 this->object->setRelCoor(this->currentKeyFrame->position + 337 (this->nextKeyFrame->position - this->currentKeyFrame->position) * (float)rand()/(float)RAND_MAX); 338 338 this->object->setRelDir(this->currentKeyFrame->direction + 339 339 (this->nextKeyFrame->direction - this->currentKeyFrame->direction)* (float)rand()/(float)RAND_MAX); 340 340 */ 341 341 } … … 401 401 void Animation3D::rLinear(float timePassed) const 402 402 { 403 this->object->setRelDir(quatSlerp( this->nextKeyFrame->direction, 404 this->currentKeyFrame->direction, 405 403 this->object->setRelDir(quatSlerp( this->nextKeyFrame->direction, 404 this->currentKeyFrame->direction, 405 timePassed/this->currentKeyFrame->duration) ); 406 406 } 407 407 … … 420 420 scale = 1.0 - sin( M_PI * timePassed / this->currentKeyFrame->duration); 421 421 422 this->object->setRelDir(quatSlerp( this->nextKeyFrame->direction, 423 this->currentKeyFrame->direction, 424 422 this->object->setRelDir(quatSlerp( this->nextKeyFrame->direction, 423 this->currentKeyFrame->direction, 424 scale) ); 425 425 } 426 426 … … 435 435 { 436 436 float scale = cos(M_PI * timePassed / this->currentKeyFrame->duration); 437 this->object->setRelDir(quatSlerp( this->nextKeyFrame->direction, 438 this->currentKeyFrame->direction, 439 437 this->object->setRelDir(quatSlerp( this->nextKeyFrame->direction, 438 this->currentKeyFrame->direction, 439 scale) ); 440 440 } 441 441 … … 458 458 { 459 459 float scale = (1.0 - expf(- timePassed * expFactorRot)); 460 this->object->setRelDir(quatSlerp( this->nextKeyFrame->direction, 461 this->currentKeyFrame->direction, 462 460 this->object->setRelDir(quatSlerp( this->nextKeyFrame->direction, 461 this->currentKeyFrame->direction, 462 scale) ); 463 463 } 464 464 -
orxonox/trunk/src/util/animation/animation3d.h
r4485 r4597 1 /*! 1 /*! 2 2 \file animation3d.h 3 3 */ … … 33 33 Animation3D(PNode* object); 34 34 virtual ~Animation3D(void); 35 35 36 36 virtual void rewind(void); 37 37 … … 40 40 41 41 virtual void tick(float dt); 42 42 43 43 private: 44 44 // animation functions -
orxonox/trunk/src/util/animation/animation_player.cc
r4485 r4597 1 /* 1 /* 2 2 orxonox - the future of 3D-vertical-scrollers 3 3 … … 26 26 \brief standard constructor 27 27 */ 28 AnimationPlayer::AnimationPlayer () 28 AnimationPlayer::AnimationPlayer () 29 29 { 30 this->setClassID(CL_ANIMATION_PLAYER, "AnimationPlayer"); 30 this->setClassID(CL_ANIMATION_PLAYER, "AnimationPlayer"); 31 this->setName("AnimationPlayer"); 31 32 32 33 33 this->animationList = new tList<Animation>(); 34 this->play(); 34 35 } 35 36 … … 43 44 44 45 !! DANGER !! when unloading the AnimationPlayer no other Function 45 should reference any Animations, from the animationList because it 46 automatically deletes them. 46 should reference any Animations, from the animationList because it 47 automatically deletes them. 47 48 This usually happens when unloading a World. 48 49 */ 49 AnimationPlayer::~AnimationPlayer () 50 AnimationPlayer::~AnimationPlayer () 50 51 { 51 52 // deleting the Animation List AND all the elements of the List … … 61 62 62 63 when adding a Animation the Animation will too be deleted when 63 the AnimationPlayer gets deleted. Consider not adding it, or 64 the AnimationPlayer gets deleted. Consider not adding it, or 64 65 unadding it with animation->notHandled(); 65 66 */ … … 80 81 /** 81 82 \brief empties the list AND deletes all the Animations 82 */ 83 */ 83 84 void AnimationPlayer::flush(void) 84 85 { … … 99 100 100 101 /** 101 \brief Ticks all the animations in animationList 102 \brief Ticks all the animations in animationList 102 103 \param timePassed the time passed since the last tick. 103 104 */ … … 110 111 Animation* anim = animIt->nextElement(); 111 112 while( anim != NULL) 112 113 114 115 116 117 118 119 120 113 { 114 anim->tick(timePassed); 115 if(unlikely(anim->ifDelete())) 116 { 117 this->animationList->remove(anim); 118 delete anim; 119 } 120 anim = animIt->nextElement(); 121 } 121 122 delete animIt; 122 123 } … … 150 151 { 151 152 if(anim->getBaseObject() == baseObject) 152 153 154 155 153 { 154 delete animIt; 155 return anim; 156 } 156 157 anim = animIt->nextElement(); 157 158 } -
orxonox/trunk/src/util/animation/animation_player.h
r4485 r4597 1 /*! 1 /*! 2 2 \file animation_player.h 3 3 */ … … 15 15 <b>AnimationPlayer usage:</b> \n 16 16 17 <b>Initialisation</b>: AnimationPlayer::getInstance() does the trick this is 17 <b>Initialisation</b>: AnimationPlayer::getInstance() does the trick this is 18 18 usually done when initializing a world \n 19 19 <b>Adding Animations</b>: create an Animation the following Way: … … 21 21 \li set some parameters: also see the specific classes for more info 22 22 \n 23 if you do not want a specific Animation to be handled by the AnimationPlayer, you have to 23 if you do not want a specific Animation to be handled by the AnimationPlayer, you have to 24 24 unload it explicitely with animation->doNotHandle(); 25 25 \n -
orxonox/trunk/src/util/animation/t_animation.h
r3982 r4597 14 14 */ 15 15 16 /*! 16 /*! 17 17 \file t_animation.h 18 18 */ … … 80 80 */ 81 81 template<class T> 82 tAnimation<T>::tAnimation (T* object, void (T::*funcToAnim)(float)) 82 tAnimation<T>::tAnimation (T* object, void (T::*funcToAnim)(float)) 83 83 { 84 84 // create a new List … … 100 100 /** 101 101 \brief standard deconstructor 102 102 103 103 deletes all the Keyframes 104 104 */ 105 105 template<class T> 106 tAnimation<T>::~tAnimation () 106 tAnimation<T>::~tAnimation () 107 107 { 108 108 // delete all the KeyFrames … … 158 158 159 159 KeyFrameF* tmpKeyFrame; 160 160 161 161 // when adding the first frame 162 162 if (this->keyFrameCount == 0) … … 170 170 // when adding the second frame 171 171 if (this->currentKeyFrame == this->nextKeyFrame) 172 172 this->nextKeyFrame = tmpKeyFrame; 173 173 this->keyFrameList->add(tmpKeyFrame); 174 174 } … … 191 191 this->localTime += dt; 192 192 if (localTime >= this->currentKeyFrame->duration) 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 this->setAnimFunc(this->currentKeyFrame->animFunc); 209 210 211 212 213 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 214 (this->object->*(funcToAnim))((this->*animFunc)(this->localTime)); 215 215 } … … 243 243 case ANIM_NEG_EXP: 244 244 { 245 246 247 245 this->animFunc = &tAnimation<T>::negExp; 246 expFactor = - 1.0 / this->currentKeyFrame->duration * logf(DELTA_X); 247 break; 248 248 } 249 249 case ANIM_QUADRATIC: … … 273 273 */ 274 274 template<class T> 275 float tAnimation<T>::linear(float timePassed) const 275 float tAnimation<T>::linear(float timePassed) const 276 276 { 277 277 return this->currentKeyFrame->value + (this->nextKeyFrame->value - this->currentKeyFrame->value) … … 287 287 { 288 288 if (timePassed * 2.0 < this->currentKeyFrame->duration) 289 return this->currentKeyFrame->value + (this->nextKeyFrame->value - this->currentKeyFrame->value) 289 return this->currentKeyFrame->value + (this->nextKeyFrame->value - this->currentKeyFrame->value) 290 290 * sin( M_PI * timePassed / this->currentKeyFrame->duration)/2; 291 else 291 else 292 292 return this->nextKeyFrame->value - (this->nextKeyFrame->value - this->currentKeyFrame->value) 293 293 * sin( M_PI * (1.0 - timePassed / this->currentKeyFrame->duration))/2; … … 350 350 float tAnimation<T>::random(float timePassed) const 351 351 { 352 return this->currentKeyFrame->value + 352 return this->currentKeyFrame->value + 353 353 (this->nextKeyFrame->value - this->currentKeyFrame->value) * 354 354 (float)rand()/(float)RAND_MAX;
Note: See TracChangeset
for help on using the changeset viewer.