| 1 | /* | 
|---|
| 2 |    orxonox - the future of 3D-vertical-scrollers | 
|---|
| 3 |  | 
|---|
| 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: ... | 
|---|
| 14 | */ | 
|---|
| 15 |  | 
|---|
| 16 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_ANIM | 
|---|
| 17 |  | 
|---|
| 18 | #include "animation.h" | 
|---|
| 19 | #include "debug.h" | 
|---|
| 20 | #include "animation_player.h" | 
|---|
| 21 |  | 
|---|
| 22 | /** | 
|---|
| 23 |  *  creates a new Animation | 
|---|
| 24 |  | 
|---|
| 25 |    This also adds the Animation automatically to the AnimationPlayer's list | 
|---|
| 26 | */ | 
|---|
| 27 | Animation::Animation() | 
|---|
| 28 | { | 
|---|
| 29 |   this->setClassID(CL_ANIMATION, "Animation"); | 
|---|
| 30 |  | 
|---|
| 31 |   // initialize a beginning KeyFrame, that will be deleted afterwards | 
|---|
| 32 |   this->keyFrameCount = 0; | 
|---|
| 33 |   this->bHandled = true; | 
|---|
| 34 |   this->bDelete = false; | 
|---|
| 35 |   this->baseObject = NULL; | 
|---|
| 36 |  | 
|---|
| 37 |   // setting default values | 
|---|
| 38 |   this->keyFramesToPlay = -1; | 
|---|
| 39 |   this->localTime = 0.0; | 
|---|
| 40 |   this->bRunning = false; | 
|---|
| 41 |  | 
|---|
| 42 |   AnimationPlayer::getInstance()->addAnimation(this); | 
|---|
| 43 | } | 
|---|
| 44 |  | 
|---|
| 45 | /** | 
|---|
| 46 |  *  destructs the Animation | 
|---|
| 47 |  | 
|---|
| 48 |    this also takes the animation out of the AnimationPlayer's list (if it is there) | 
|---|
| 49 | */ | 
|---|
| 50 | Animation::~Animation() | 
|---|
| 51 | { | 
|---|
| 52 |   this->doNotHandle(); | 
|---|
| 53 | } | 
|---|
| 54 |  | 
|---|
| 55 | /** | 
|---|
| 56 |  *  tells the AnimationPlayer, that we do not wish to  handle this animation | 
|---|
| 57 |    automatically. | 
|---|
| 58 |  | 
|---|
| 59 |    This means that it will not be ticked, and not be deleted with the AnimationPlayer | 
|---|
| 60 | */ | 
|---|
| 61 | void Animation::doNotHandle() | 
|---|
| 62 | { | 
|---|
| 63 |   if (this->bHandled) | 
|---|
| 64 |     AnimationPlayer::getInstance()->removeAnimation(this); | 
|---|
| 65 | } | 
|---|
| 66 |  | 
|---|
| 67 | /** | 
|---|
| 68 |  *  Sets the infinitymode | 
|---|
| 69 |  * @param postInfinity How the Animation should advance after the last Keyframe | 
|---|
| 70 | */ | 
|---|
| 71 | void Animation::setInfinity(ANIM_INFINITY postInfinity) | 
|---|
| 72 | { | 
|---|
| 73 |   this->postInfinity = postInfinity; | 
|---|
| 74 | } | 
|---|
| 75 |  | 
|---|
| 76 | /** | 
|---|
| 77 |  *  handles the Animation if it gets out of boundraries eg. if animation is finished. | 
|---|
| 78 | */ | 
|---|
| 79 | void Animation::handleInfinity() | 
|---|
| 80 | { | 
|---|
| 81 |   switch (this->postInfinity) | 
|---|
| 82 |     { | 
|---|
| 83 |     case ANIM_INF_CONSTANT: | 
|---|
| 84 |       this->localTime = 0.0; | 
|---|
| 85 |       this->bRunning = false; | 
|---|
| 86 |       break; | 
|---|
| 87 |     case ANIM_INF_REPLAY: | 
|---|
| 88 |       this->rewind(); | 
|---|
| 89 |       this->bRunning = true; | 
|---|
| 90 |       break; | 
|---|
| 91 |     case ANIM_INF_REWIND: | 
|---|
| 92 |       this->stop(); | 
|---|
| 93 |       break; | 
|---|
| 94 |     case ANIM_INF_DELETE: // this will possibly never be made | 
|---|
| 95 |       this->bDelete = true; | 
|---|
| 96 |       break; | 
|---|
| 97 |     } | 
|---|
| 98 | } | 
|---|
| 99 |  | 
|---|
| 100 | /** | 
|---|
| 101 |  *  plays the animation back from the current Time forward | 
|---|
| 102 | */ | 
|---|
| 103 | void Animation::play() | 
|---|
| 104 | { | 
|---|
| 105 |   this->keyFramesToPlay = -1; | 
|---|
| 106 |   this->bRunning = true; | 
|---|
| 107 | } | 
|---|
| 108 |  | 
|---|
| 109 | /** | 
|---|
| 110 |  *  plays the Next n keyframes | 
|---|
| 111 |  * @param n the Count of keyFrames to play. | 
|---|
| 112 | */ | 
|---|
| 113 | void Animation::playNextKeyframes(int n) | 
|---|
| 114 | { | 
|---|
| 115 |   this->keyFramesToPlay = n-1; | 
|---|
| 116 |   this->bRunning = true; | 
|---|
| 117 | } | 
|---|
| 118 |  | 
|---|
| 119 | /** | 
|---|
| 120 |  *  Stops the animation. eg. pause(); rewind(); | 
|---|
| 121 | */ | 
|---|
| 122 | void Animation::stop() | 
|---|
| 123 | { | 
|---|
| 124 |   this->keyFramesToPlay = -1; | 
|---|
| 125 |   this->rewind(); | 
|---|
| 126 |   this->bRunning = true; | 
|---|
| 127 |   this->tick(0.0); | 
|---|
| 128 |   this->bRunning = false; | 
|---|
| 129 | } | 
|---|
| 130 |  | 
|---|
| 131 | /** | 
|---|
| 132 |  *  Pauses the animation. Stays at the current Time | 
|---|
| 133 | */ | 
|---|
| 134 | void Animation::pause() | 
|---|
| 135 | { | 
|---|
| 136 |   this->bRunning = false; | 
|---|
| 137 | } | 
|---|
| 138 |  | 
|---|
| 139 | /** | 
|---|
| 140 |  *  replays the animation, eg. rewind();play(); | 
|---|
| 141 | */ | 
|---|
| 142 | void Animation::replay() | 
|---|
| 143 | { | 
|---|
| 144 |   this->rewind(); | 
|---|
| 145 |   this->play(); | 
|---|
| 146 | } | 
|---|