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