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