Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/simple_animation.cc @ 3719

Last change on this file since 3719 was 3719, checked in by patrick, 19 years ago

orxonox/trunk: implementing simpleanimation

File size: 5.7 KB
Line 
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
23using 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*/
31KeyFrame::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*/
46KeyFrame::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*/
58KeyFrame::~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*/
69void 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*/
84void 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*/
97SimpleAnimation::SimpleAnimation (PNode* parent) 
98{
99   this->setClassName ("SimpleAnimation");
100   this->frames = new tList<KeyFrame>();
101   this->localTime = 0;
102   this->bRunning = false;
103   this->parent = parent;
104   this->currentFrame = NULL;
105   this->lastFrame = NULL;
106}
107
108
109/**
110   \brief standard deconstructor
111
112*/
113SimpleAnimation::~SimpleAnimation () 
114{
115  tIterator<KeyFrame>* iterator = this->frames->getIterator();
116  KeyFrame* frame = iterator->nextElement(); 
117  while( frame != NULL) 
118    { 
119      delete frame;
120      frame = iterator->nextElement();
121    }
122  delete iterator;
123  delete this->frames;
124}
125
126
127
128/**
129   \brief adds a keyframe with properties
130   \param the point of the object
131   \param and the orientation of it
132   \param at this time
133*/
134void SimpleAnimation::addKeyFrame(Vector* point, Quaternion* orientation, float time)
135{
136  KeyFrame* frame = new KeyFrame(point, orientation, time);
137  this->frames->add(frame);
138}
139
140
141/**
142   \brief adds a keyframe with properties
143   \param the point of the object
144   \param and the orientation of it
145   \param at this time
146   \param function of the velocity of the movement
147*/
148void SimpleAnimation::addKeyFrame(Vector* point, Quaternion* orientation, float time, movementMode mode)
149{
150  KeyFrame* frame = new KeyFrame(point, orientation, time, mode);
151  this->frames->add(frame);
152}
153
154/**
155   \brief adds a already defined keyframe
156   \param the keyframe to add
157*/
158void SimpleAnimation::addKeyFrame(KeyFrame* frame)
159{
160  if( frame != NULL)
161    this->frames->add(frame);
162}
163
164
165/**
166   \brief clear the list of keyframes, deleting all keyframes included
167*/
168void SimpleAnimation::reset()
169{
170  tIterator<KeyFrame>* iterator = this->frames->getIterator();
171  KeyFrame* frame = iterator->nextElement(); 
172  while( frame != NULL) 
173    { 
174      delete frame;
175      frame = iterator->nextElement();
176    }
177  delete iterator;
178  delete this->frames;
179
180  this->frames = new tList<KeyFrame>();
181  this->localTime = 0;
182  this->bRunning = false;
183
184  this->currentFrame = NULL;
185  this->lastFrame = NULL;
186}
187
188/**
189   \brief starts the animation, therefore listens to tick signals
190*/
191void SimpleAnimation::start()
192{
193  if( this->bRunning)
194    {
195      PRINTF(2)("SimpleAnimatin is already running. You are trying to start it again.\n");
196    return;
197    }
198 
199  this->localTime = 0;
200  this->lastFrame = this->frames->firstElement();
201  this->currentFrame = this->frames->nextElement(this->currentFrame);
202  this->bRunning = true;
203}
204
205
206/**
207   \brief stops the animation, immune to tick signals
208*/
209void SimpleAnimation::stop()
210{
211  this->bRunning = false;
212}
213
214/**
215   \brief stops and then starts the animation from begining
216*/
217void SimpleAnimation::restart()
218{
219  this->localTime = 0;
220  this->lastFrame = this->frames->firstElement();
221  this->currentFrame = this->frames->nextElement(this->currentFrame);
222  this->bRunning = true;
223}
224
225/**
226   \brief pauses the animation until resumed
227*/
228void SimpleAnimation::pause()
229{
230  this->bRunning = false;
231}
232
233/**
234   \brief resumes a pause, if not paused, no effect
235*/
236void SimpleAnimation::resume()
237{
238  this->bRunning = true;
239}
240
241
242/**
243   \brief heart beat, next animation step
244*/
245void SimpleAnimation::tick(float time)
246{
247  if( !this->bRunning)
248    return;
249
250  this->localTime += time;
251  /* first get the current frame via time-stamps */ 
252  while( this->localTime > this->currentFrame->time)
253    {
254      printf("SimpleAnimation::tick(...) - changing Frame");
255      this->currentFrame = this->frames->nextElement(this->currentFrame);
256      this->localTime -= this->currentFrame->time;
257    }
258 
259 
260
261  /* now animate it */
262  switch( this->mode)
263    {
264    case LINEAR:
265     
266      break;
267    case EXP:
268     
269      break;
270    case NEG_EXP:
271     
272      break;
273    case SIN:
274     
275      break;
276    case COS:
277     
278      break;
279    case QUADRATIC:
280     
281      break;
282    default:
283      break;
284    }
285}
Note: See TracBrowser for help on using the repository browser.