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