[3573] | 1 | |
---|
| 2 | |
---|
| 3 | /* |
---|
| 4 | orxonox - the future of 3D-vertical-scrollers |
---|
| 5 | |
---|
| 6 | Copyright (C) 2004 orx |
---|
| 7 | |
---|
| 8 | This program is free software; you can redistribute it and/or modify |
---|
| 9 | it under the terms of the GNU General Public License as published by |
---|
| 10 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 11 | any later version. |
---|
| 12 | |
---|
| 13 | ### File Specific: |
---|
| 14 | main-programmer: Patrick Boenzli |
---|
| 15 | co-programmer: ... |
---|
| 16 | */ |
---|
| 17 | |
---|
| 18 | |
---|
| 19 | #include "simple_animation.h" |
---|
| 20 | #include "stdincl.h" |
---|
| 21 | #include "p_node.h" |
---|
| 22 | |
---|
| 23 | using namespace std; |
---|
| 24 | |
---|
| 25 | /** |
---|
| 26 | \brief standard constructor |
---|
| 27 | \param the point of the object |
---|
| 28 | \param and the orientation of it |
---|
| 29 | \param at this time |
---|
| 30 | */ |
---|
| 31 | KeyFrame::KeyFrame(Vector* point, Quaternion* orientation, float time) |
---|
| 32 | { |
---|
| 33 | this->setRelCoor(point); |
---|
| 34 | this->setRelDir(orientation); |
---|
| 35 | this->time = time; |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | |
---|
| 39 | /** |
---|
| 40 | \brief standard constructor |
---|
| 41 | \param the point of the object |
---|
| 42 | \param and the orientation of it |
---|
| 43 | \param at this time |
---|
| 44 | \param function of the velocity of the movement |
---|
| 45 | */ |
---|
| 46 | KeyFrame::KeyFrame(Vector* point, Quaternion* orientation, float time, movementMode mode) |
---|
| 47 | { |
---|
| 48 | this->setRelCoor(point); |
---|
| 49 | this->setRelDir(orientation); |
---|
| 50 | this->time = time; |
---|
| 51 | this->mode = mode; |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | |
---|
| 55 | /** |
---|
| 56 | \brief standard deconstructor |
---|
| 57 | */ |
---|
| 58 | KeyFrame::~KeyFrame() |
---|
| 59 | { |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | |
---|
| 63 | /** |
---|
| 64 | \brief sets the important properties of a Keyframe |
---|
| 65 | \param the point of the object |
---|
| 66 | \param and the orientation of it |
---|
| 67 | \param at this time |
---|
| 68 | */ |
---|
| 69 | void KeyFrame::set(Vector* point, Quaternion* orientation, float time) |
---|
| 70 | { |
---|
| 71 | this->setRelCoor(point); |
---|
| 72 | this->setRelDir(orientation); |
---|
| 73 | this->time = time; |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | |
---|
| 77 | /** |
---|
| 78 | \brief sets the important properties of a Keyframe |
---|
| 79 | \param the point of the object |
---|
| 80 | \param and the orientation of it |
---|
| 81 | \param at this time |
---|
| 82 | \param function of the velocity of the movement |
---|
| 83 | */ |
---|
| 84 | void KeyFrame::set(Vector* point, Quaternion* orientation, float time, movementMode mode) |
---|
| 85 | { |
---|
| 86 | this->setRelCoor(point); |
---|
| 87 | this->setRelDir(orientation); |
---|
| 88 | this->time = time; |
---|
| 89 | this->mode = mode; |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | |
---|
| 93 | |
---|
| 94 | /** |
---|
| 95 | \brief standard constructor |
---|
| 96 | */ |
---|
| 97 | SimpleAnimation::SimpleAnimation (PNode* parent) |
---|
| 98 | { |
---|
| 99 | this->setClassName ("SimpleAnimation"); |
---|
| 100 | this->frames = new tList<KeyFrame>(); |
---|
| 101 | this->localTime = 0; |
---|
| 102 | this->bPause = false; |
---|
| 103 | this->parent = parent; |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | |
---|
| 107 | /** |
---|
| 108 | \brief standard deconstructor |
---|
| 109 | |
---|
| 110 | */ |
---|
| 111 | SimpleAnimation::~SimpleAnimation () |
---|
| 112 | { |
---|
[3661] | 113 | tIterator<KeyFrame>* iterator = this->frames->getIterator(); |
---|
| 114 | KeyFrame* frame = iterator->nextElement(); |
---|
[3573] | 115 | while( frame != NULL) |
---|
| 116 | { |
---|
| 117 | delete frame; |
---|
[3661] | 118 | frame = iterator->nextElement(); |
---|
[3573] | 119 | } |
---|
[3661] | 120 | delete iterator; |
---|
[3573] | 121 | delete this->frames; |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | |
---|
| 125 | |
---|
| 126 | /** |
---|
| 127 | \brief adds a keyframe with properties |
---|
| 128 | \param the point of the object |
---|
| 129 | \param and the orientation of it |
---|
| 130 | \param at this time |
---|
| 131 | */ |
---|
| 132 | void SimpleAnimation::addKeyFrame(Vector* point, Quaternion* orientation, float time) |
---|
| 133 | { |
---|
| 134 | KeyFrame* frame = new KeyFrame(point, orientation, time); |
---|
| 135 | this->frames->add(frame); |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | |
---|
| 139 | /** |
---|
| 140 | \brief adds a keyframe with properties |
---|
| 141 | \param the point of the object |
---|
| 142 | \param and the orientation of it |
---|
| 143 | \param at this time |
---|
| 144 | \param function of the velocity of the movement |
---|
| 145 | */ |
---|
| 146 | void SimpleAnimation::addKeyFrame(Vector* point, Quaternion* orientation, float time, movementMode mode) |
---|
| 147 | { |
---|
| 148 | KeyFrame* frame = new KeyFrame(point, orientation, time, mode); |
---|
| 149 | this->frames->add(frame); |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | /** |
---|
| 153 | \brief adds a already defined keyframe |
---|
| 154 | \param the keyframe to add |
---|
| 155 | */ |
---|
| 156 | void SimpleAnimation::addKeyFrame(KeyFrame* frame) |
---|
| 157 | { |
---|
[3717] | 158 | if( frame != NULL) |
---|
| 159 | this->frames->add(frame); |
---|
[3573] | 160 | } |
---|
| 161 | |
---|
| 162 | |
---|
| 163 | /** |
---|
| 164 | \brief clear the list of keyframes, deleting all keyframes included |
---|
| 165 | */ |
---|
| 166 | void SimpleAnimation::reset() |
---|
| 167 | { |
---|
[3661] | 168 | tIterator<KeyFrame>* iterator = this->frames->getIterator(); |
---|
| 169 | KeyFrame* frame = iterator->nextElement(); |
---|
[3573] | 170 | while( frame != NULL) |
---|
| 171 | { |
---|
| 172 | delete frame; |
---|
[3661] | 173 | frame = iterator->nextElement(); |
---|
[3573] | 174 | } |
---|
[3661] | 175 | delete iterator; |
---|
[3573] | 176 | delete this->frames; |
---|
| 177 | |
---|
| 178 | this->frames = new tList<KeyFrame>(); |
---|
| 179 | this->localTime = 0; |
---|
| 180 | this->bPause = false; |
---|
| 181 | |
---|
| 182 | } |
---|
| 183 | |
---|
| 184 | /** |
---|
| 185 | \brief starts the animation, therefore listens to tick signals |
---|
| 186 | */ |
---|
| 187 | void SimpleAnimation::start() |
---|
| 188 | {} |
---|
| 189 | |
---|
| 190 | |
---|
| 191 | /** |
---|
| 192 | \brief stops the animation, immune to tick signals |
---|
| 193 | */ |
---|
| 194 | void SimpleAnimation::stop() |
---|
| 195 | {} |
---|
| 196 | |
---|
| 197 | /** |
---|
| 198 | \brief stops and then starts the animation from begining |
---|
| 199 | */ |
---|
| 200 | void SimpleAnimation::restart() |
---|
| 201 | { |
---|
| 202 | this->localTime = 0; |
---|
| 203 | this->bPause = false; |
---|
| 204 | } |
---|
| 205 | |
---|
| 206 | /** |
---|
| 207 | \brief pauses the animation until resumed |
---|
| 208 | */ |
---|
| 209 | void SimpleAnimation::pause() |
---|
| 210 | { |
---|
| 211 | this->bPause = true; |
---|
| 212 | } |
---|
| 213 | |
---|
| 214 | /** |
---|
| 215 | \brief resumes a pause, if not paused, no effect |
---|
| 216 | */ |
---|
| 217 | void SimpleAnimation::resume() |
---|
| 218 | { |
---|
| 219 | this->bPause = false; |
---|
| 220 | } |
---|
| 221 | |
---|
| 222 | |
---|
| 223 | /** |
---|
| 224 | \brief heart beat, next animation step |
---|
| 225 | */ |
---|
| 226 | void SimpleAnimation::tick(float time) |
---|
| 227 | { |
---|
| 228 | if(!this->bPause) |
---|
| 229 | { |
---|
[3717] | 230 | switch( this->mode) |
---|
| 231 | { |
---|
| 232 | case LINEAR: |
---|
| 233 | |
---|
| 234 | break; |
---|
| 235 | case EXP: |
---|
[3573] | 236 | |
---|
[3717] | 237 | break; |
---|
| 238 | case NEG_EXP: |
---|
[3573] | 239 | |
---|
[3717] | 240 | break; |
---|
| 241 | case SIN: |
---|
[3573] | 242 | |
---|
[3717] | 243 | break; |
---|
| 244 | case COS: |
---|
| 245 | |
---|
| 246 | break; |
---|
| 247 | case QUADRATIC: |
---|
| 248 | |
---|
| 249 | break; |
---|
| 250 | default: |
---|
| 251 | break; |
---|
| 252 | } |
---|
[3573] | 253 | } |
---|
| 254 | } |
---|