Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: added quick-animation for FAST, bad animations that suffice for the properties particles over time

File size: 2.9 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/**
31   \brief standard constructor
32*/
33QuickAnimation::QuickAnimation (float rangeStart, float valueStart, float rangeEnd, float valueEnd)
34{
35   this->setClassName("QuickAnimation");
36
37   this->first = this->current = new QuickKeyFrame;
38   this->current->positionStart = rangeStart;
39   this->current->positionEnd = rangeEnd;
40   this->current->valueStart = valueStart;
41   this->current->valueEnd = valueEnd;
42   this->current->next = NULL;
43}
44
45
46/**
47   \brief standard deconstructor
48
49*/
50QuickAnimation::~QuickAnimation () 
51{
52  this->current = this->first;
53  QuickKeyFrame delKF;
54 
55  while (this->current != NULL)
56    {
57      this->first = this->current->next;
58      delete this->current;
59      this->current = this->first;
60    }
61
62}
63
64
65void QuickAnimation::addEntry(float position, float value)
66{
67  this->current = this->first;
68  if (position < this->current->positionStart)
69    {
70      this->current = new QuickKeyFrame;
71
72      this->current->positionStart = position;
73      this->current->positionEnd = this->first->positionStart;
74
75      this->current->valueStart = value;
76      this->current->valueEnd = this->first->valueStart;
77     
78      this->current->next = this->first;
79      this->first = this->current;
80    }
81 
82  while(this->current != NULL)
83    {
84      if (this->current->positionStart < position)
85        {
86          QuickKeyFrame* tmpKey = new QuickKeyFrame;
87          tmpKey->positionStart = position;
88          tmpKey->positionEnd = this->current->positionEnd;
89          tmpKey->valueStart = value;
90          tmpKey->valueEnd = this->current->valueEnd;
91          tmpKey->next = this->current->next;
92         
93          this->current->positionEnd = tmpKey->positionStart;
94          this->current->valueEnd = tmpKey->valueStart;
95        }
96    }
97}
98
99
100float QuickAnimation::getValue(float position)
101{
102  while (likely (this->current->positionStart > position || this->current->positionEnd < position))
103    {
104      if (likely(this->current->next != NULL))
105        this->current = this->current->next;
106      else
107        {
108          if (unlikely(this->first->positionStart > position))
109            {
110              PRINTF(2)("Position out of range. chose %f, min is: %f, max is\n", position, this->first->positionStart, this->current->positionEnd);
111              return 0;
112            }
113          this->current = this->first;
114        }
115    }
116  return this->current->valueStart + (this->current->positionEnd - position) *
117    (this->current->valueEnd - this->current->valueStart) /
118    (this->current->positionEnd - this->current->positionStart);
119}
120
Note: See TracBrowser for help on using the repository browser.