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 | \brief creates a new Animation |
---|
24 | |
---|
25 | This also adds the Animation automatically to the AnimationPlayer's list |
---|
26 | */ |
---|
27 | Animation::Animation(void) |
---|
28 | { |
---|
29 | // initialize a beginning KeyFrame, that will be deleted afterwards |
---|
30 | this->keyFrameCount = 0; |
---|
31 | this->bHandled = true; |
---|
32 | this->bDelete = false; |
---|
33 | this->baseObject = NULL; |
---|
34 | |
---|
35 | // setting default values |
---|
36 | this->localTime = 0.0; |
---|
37 | this->bRunning = true; |
---|
38 | |
---|
39 | AnimationPlayer::getInstance()->addAnimation(this); |
---|
40 | } |
---|
41 | |
---|
42 | /** |
---|
43 | \brief destructs the Animation |
---|
44 | |
---|
45 | this also takes the animation out of the AnimationPlayer's list (if it is there) |
---|
46 | */ |
---|
47 | Animation::~Animation(void) |
---|
48 | { |
---|
49 | this->doNotHandle(); |
---|
50 | } |
---|
51 | |
---|
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 | */ |
---|
58 | void Animation::doNotHandle(void) |
---|
59 | { |
---|
60 | if (this->bHandled) |
---|
61 | AnimationPlayer::getInstance()->removeAnimation(this); |
---|
62 | } |
---|
63 | |
---|
64 | /** |
---|
65 | \brief Sets the infinitymode |
---|
66 | \param postInfinity How the Animation should advance after the last Keyframe |
---|
67 | */ |
---|
68 | void Animation::setInfinity(ANIM_INFINITY postInfinity) |
---|
69 | { |
---|
70 | this->postInfinity = postInfinity; |
---|
71 | } |
---|
72 | |
---|
73 | /** |
---|
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; |
---|
87 | case ANIM_INF_REWIND: |
---|
88 | this->stop(); |
---|
89 | break; |
---|
90 | case ANIM_INF_DELETE: // this will possibly never be made |
---|
91 | this->bDelete = true; |
---|
92 | break; |
---|
93 | } |
---|
94 | } |
---|
95 | |
---|
96 | /** |
---|
97 | \brief plays the animation back from the current Time forward |
---|
98 | */ |
---|
99 | void Animation::play() |
---|
100 | { |
---|
101 | this->bRunning = true; |
---|
102 | } |
---|
103 | |
---|
104 | /** |
---|
105 | \brief Stops the animation. eg. pause(); rewind(); |
---|
106 | */ |
---|
107 | void Animation::stop() |
---|
108 | { |
---|
109 | this->rewind(); |
---|
110 | this->bRunning = true; |
---|
111 | this->tick(0.0); |
---|
112 | this->bRunning = false; |
---|
113 | } |
---|
114 | |
---|
115 | /** |
---|
116 | \brief Pauses the animation. Stays at the current Time |
---|
117 | */ |
---|
118 | void Animation::pause() |
---|
119 | { |
---|
120 | this->bRunning = false; |
---|
121 | } |
---|
122 | |
---|
123 | /** |
---|
124 | \brief replays the animation, eg. rewind();play(); |
---|
125 | */ |
---|
126 | void Animation::replay() |
---|
127 | { |
---|
128 | this->rewind(); |
---|
129 | this->bRunning = true; |
---|
130 | } |
---|