Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/lib/particles/quick_animation.cc @ 4836

Last change on this file since 4836 was 4836, checked in by bensch, 19 years ago

orxonox/trunk: renamed all the \param → @param and so on in Doxygen tags.
Thanks a lot to the kDevelop team. this took since the last commit :)

File size: 6.2 KB
RevLine 
[4597]1/*
[1853]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.
[1855]10
11   ### File Specific:
12   main-programmer: ...
13   co-programmer: ...
[1853]14*/
15
[3955]16//#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_
[1853]17
[4415]18#include "quick_animation.h"
[1853]19
[4415]20#include "compiler.h"
21#include "debug.h"
22#ifndef NULL
23#define NULL 0
24#endif
25
26
[1856]27using namespace std;
[1853]28
[3245]29/**
[4836]30 *  standard constructor
[3245]31*/
[4746]32QuickAnimation::QuickAnimation ()
[3365]33{
[4597]34   this->setClassID(CL_QUICK_ANIMATION, "QuickAnimation");
[4320]35
[4654]36   // initialize the First KeyFrame (will be deleted if a new one gets created)
37   this->count = 0;
38   this->first = this->current = new QuickKeyFrame;
39   this->first->next = this->first->prev = this->first;
40   this->first->position = 0.0;
41   this->first->value = 0.0;
[3365]42}
[1853]43
[3245]44/**
[4836]45 *  deletes all the deconstructor stuff
[3245]46*/
[4746]47QuickAnimation::~QuickAnimation ()
[3543]48{
[4415]49  this->current = this->first;
[4654]50  QuickKeyFrame* delKF = this->first;
[4597]51
[4654]52  do
53  {
54    delKF = this->current;
55    this->current = this->current->next;
56    delete delKF;
57  }  while (this->current != this->first);
58
[3543]59}
[4415]60
[4421]61/**
[4836]62 *  adds a new entry to the list of keyframes
63 * @param position the position to add the key to
64 * @param value the Value to set for the position
65 * @returns false if the key existed already for a given position
[4421]66*/
[4654]67void QuickAnimation::addEntry(float position, float value)
[4415]68{
[4654]69  // create the new KeyFrame
70  QuickKeyFrame* newKey = new QuickKeyFrame;
71  newKey->position = position;
72  newKey->value = value;
73
74  // if we add a KeyFrame for the first Time:
75  if (unlikely (this->count == 0))
76  {
77    delete this->first;
78
79    newKey->next  = newKey;
80    newKey->prev  = newKey;
81    this->first   = newKey;
82    this->current = newKey;
83  }
84  // if the KeyFrame is in front of the FIRST keyFrame
85  else if (this->first->position > position)
86  {
87    newKey->next = this->first;
88    newKey->prev = this->first->prev;
89    newKey->prev->next = newKey;
90    newKey->next->prev = newKey;
91
92    this->first = newKey; // the new Key becomes the FIRST.
93  }
94  // if the KeyFrame is at the End of the Animation
95  else if (this->first->prev->position < position)
96  {
97    newKey->next = this->first;
98    newKey->prev = this->first->prev;
99    newKey->prev->next = newKey;
100    newKey->next->prev = newKey;
101  }
102  // if the Key is between two frames.
103  else
104  {
105    this->current = this->first;
106    do
[4415]107    {
[4654]108      if (this->current->position < position && this->current->next->position > position)
[4597]109        break;
[4421]110      // if it is the same as an already existing keyframe
111      else if (this->current->position == position)
[4654]112      {
113        this->current->value = value;
114        delete newKey;
115        return;
116      }
[4421]117      this->current = this->current->next;
[4654]118    } while (this->current != this->first);
[4415]119
[4654]120    newKey->next = this->current->next;
121    newKey->prev = this->current;
122    newKey->next->prev = newKey;
123    newKey->prev->next = newKey;
124  }
[4421]125  this->current = this->first;
[4654]126  ++this->count;
[4415]127}
128
[4421]129/**
[4836]130 *  changes an entry in the region of position
131 * @param position the Position of an existing keyframe
132 * @param region a deviation of the existing keyframe (like a delta in witch to search for
133 * @param value the new Value
[4654]134
[4656]135   if the Entry at the in the region of the specified position is found, it will be changed.
136    Otherwise a new KeyFrame will be created with value at position.
[4836]137   @todo rimplement
[4425]138*/
[4654]139void QuickAnimation::changeEntry(float position, float value, float region)
[4425]140{
[4649]141
[4656]142  if ((this->first->position > position + region) || this->first->prev->position < position - region || this->count == 0)
143    this->addEntry(position, value);
144  else
145  {
146    this->current = this->first;
147    do
148    {
149      if (this->current->position > position + region)
150      {
151        this->addEntry(position, value);
152        return;
153      }
154      if (this->current->position < position+region && this->current->position > position-region)
155      {
156        this->current->value = value;
157        return;
158      }
159      this->current = this->current->next;
160    }  while (this->current != this->first);
161  }
[4425]162}
163
[4597]164
[4657]165/**
166 * removes a KeyFrame from the List.
167 * @param position
168 * @return
169 */
170void QuickAnimation::removeEntry(float position)
171{
[4425]172  this->current = this->first;
[4597]173
[4657]174  if (this->count <= 0)
[4425]175  {
[4657]176    this->current->value = 0.0;
177    this->current->position = 0.0;
178    count = 0;
179    return;
180  }
181  else
[4425]182  {
[4657]183    do
184    {
185      if (this->current->position == position)
186      {
187        if (this->current == this->first)
188          this->first = this->first->next;
189        this->current->next->prev = this->current->prev;
190        this->current->prev->next = this->current->next;
191        delete this->current;
192        break;
193      }
194      this->current = this->current->next;
195    } while (this->current != this->first);
[4597]196
[4657]197    count --;
198    this->current = this->first;
[4425]199  }
[4657]200}
[4425]201
[4657]202
[4425]203/**
[4836]204 *  returns the value of the animation at a certain position
205 * @param position the position to get the value from :)
[4421]206*/
[4597]207float QuickAnimation::getValue(float position)
[4415]208{
[4654]209  while (true)
210  {
211    // if we have a match
212    if (likely(this->current->position <= position && this->current->next->position >= position))
[4421]213      return this->current->value + (this->current->next->value - this->current->value)
[4654]214          * ((position-this->current->position) / (this->current->next->position -this->current->position));
215
216    else if (unlikely(this->first->prev->position < position))
217      return this->first->prev->value;
218    else if (unlikely(this->first->position > position))
219      return this->first->value;
220    else if(likely(this->current->next->position < position))
221      this->current = this->current->next;
222    else if (likely(this->current->position > position))
223      this->current = this->current->prev;
224  }
[4415]225}
226
[4479]227/**
[4836]228 *  outputs some nice information about this class
[4479]229*/
[4746]230void QuickAnimation::debug()
[4421]231{
232  this->current = this->first;
233
[4654]234  PRINT(0)("QuickAnim(entries:%d)::(position, value)", this->count);
235  do
[4421]236    {
237      PRINT(0)("->(%f, %f)", this->current->position, this->current->value);
238      this->current = this->current->next;
[4654]239    } while(this->current != this->first);
[4421]240
241  PRINT(0)("\n");
242  this->current = this->first;
243}
Note: See TracBrowser for help on using the repository browser.