Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: subproject Particles looks good again

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   \brief standard deconstructor
41
42*/
43QuickAnimation::~QuickAnimation (void)
44{
45  this->current = this->first;
46  QuickKeyFrame delKF;
47
48  while (this->current != NULL)
49    {
50      this->first = this->current->next;
51      delete this->current;
52      this->current = this->first;
53    }
54}
55
56/**
57   \brief adds a new entry to the list of keyframes
58   \param position the position to add the key to
59   \param value the Value to set for the position
60   \returns false if the key existed already for a given position
61*/
62bool QuickAnimation::addEntry(float position, float value)
63{
64  this->current = this->first;
65  while (this->current != NULL)
66    {
67      // if it is between some keyframes
68      if ((!this->current->next && this->current->position < position)
69          || (this->current->position < position && this->current->next->position > position))
70        break;
71      // if it is the same as an already existing keyframe
72      else if (this->current->position == position)
73        return false;
74      this->current = this->current->next;
75    }
76
77  QuickKeyFrame* newKey = new QuickKeyFrame;
78  if (this->first == NULL)
79    {
80      this->first = newKey;
81      this->current = newKey;
82      newKey->next = NULL;
83    }
84  else
85    {
86      newKey->next = this->current->next;
87      this->current->next = newKey;
88    }
89  newKey->value = value;
90  newKey->position = position;
91
92  this->current = this->first;
93
94  return true;
95}
96
97/**
98   \brief changes an entry in the region of position
99   \param position the Position of an existing keyframe
100   \param region a deviation of the existing keyframe (like a delta in witch to search for
101   \param value the new Value
102*/
103bool QuickAnimation::changeEntry(float position, float value, float region)
104{
105  this->current = this->first;
106  while (this->current)
107    {
108      if (this->current->position < position+region && this->current->position > position-region)
109        {
110          this->current->value = value;
111          return true;
112        }
113      this->current = this->current->next;
114    }
115  this->current = this->first;
116
117  this->addEntry(position, value);
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.