Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: setClassID implemented in all files

File size: 4.4 KB
Line 
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: ...
13   co-programmer: ...
14*/
15
16//#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_
17
18#include "quick_animation.h"
19
20#include "compiler.h"
21#include "debug.h"
22#ifndef NULL
23#define NULL 0
24#endif
25
26
27using namespace std;
28
29/**
30   \brief standard constructor
31*/
32QuickAnimation::QuickAnimation (void)
33{
34   this->setClassID(CL_QUICK_ANIMATION, "QuickAnimation");
35
36   this->first = this->current = NULL;
37}
38
39
40/**
41   \brief standard deconstructor
42
43*/
44QuickAnimation::~QuickAnimation (void)
45{
46  this->current = this->first;
47  QuickKeyFrame delKF;
48
49  while (this->current != NULL)
50    {
51      this->first = this->current->next;
52      delete this->current;
53      this->current = this->first;
54    }
55}
56
57/**
58   \brief adds a new entry to the list of keyframes
59   \param position the position to add the key to
60   \param value the Value to set for the position
61   \returns false if the key existed already for a given position
62*/
63bool QuickAnimation::addEntry(float position, float value)
64{
65  this->current = this->first;
66  while (this->current != NULL)
67    {
68      // if it is between some keyframes
69      if ((!this->current->next && this->current->position < position)
70          || (this->current->position < position && this->current->next->position > position))
71        break;
72      // if it is the same as an already existing keyframe
73      else if (this->current->position == position)
74        return false;
75      this->current = this->current->next;
76    }
77
78  QuickKeyFrame* newKey = new QuickKeyFrame;
79  if (this->first == NULL)
80    {
81      this->first = newKey;
82      this->current = newKey;
83      newKey->next = NULL;
84    }
85  else
86    {
87      newKey->next = this->current->next;
88      this->current->next = newKey;
89    }
90  newKey->value = value;
91  newKey->position = position;
92
93  this->current = this->first;
94
95  return true;
96}
97
98/**
99   \brief changes an entry in the region of position
100   \param position the Position of an existing keyframe
101   \param region a deviation of the existing keyframe (like a delta in witch to search for
102   \param value the new Value
103*/
104bool QuickAnimation::changeEntry(float position, float value, float region)
105{
106  this->current = this->first;
107  while (this->current)
108    {
109      if (this->current->position < position+region && this->current->position > position-region)
110        {
111          this->current->value = value;
112          return true;
113        }
114      this->current = this->current->next;
115    }
116  this->current = this->first;
117  return false;
118}
119
120/*
121  \param position The position where to find the Node to kill
122
123  bool QuickAnimation::removeEntry(float position)
124  {
125  this->current = this->first;
126  QuickKeyFrame* last =
127
128  while (this->current)
129  {
130  if (this->current->position == position)
131  {
132
133
134  }
135  this->current = this->current->next;
136  }
137  this->current = this->first;
138  }
139*/
140
141/**
142   \brief returns the value of the animation at a certain position
143   \param position the position to get the value from :)
144*/
145float QuickAnimation::getValue(float position)
146{
147  if (unlikely(this->first == NULL))
148    return 0.0;
149  else if (unlikely (this->first->next == NULL))
150    return this->first->value;
151  else
152    {
153      if (unlikely(position < this->current->position))
154        {
155          if (position <= this->first->position)
156            return this->first->value;
157          this->current = this->first;
158        }
159      while (likely(this->current->next != NULL && position > this->current->next->position))
160        this->current = this->current->next;
161      if (this->current->next == NULL)
162        return this->current->value;
163
164      return this->current->value + (this->current->next->value - this->current->value)
165        * ((position-this->current->position) / (this->current->next->position -this->current->position));
166    }
167}
168
169/**
170   \brief outputs some nice information about this class
171*/
172void QuickAnimation::debug(void)
173{
174  this->current = this->first;
175
176  PRINT(0)("QuickAnim:: (position, value)");
177  while(this->current)
178    {
179      PRINT(0)("->(%f, %f)", this->current->position, this->current->value);
180      this->current = this->current->next;
181    }
182
183  PRINT(0)("\n");
184  this->current = this->first;
185}
Note: See TracBrowser for help on using the repository browser.