forked from nasa/dcapp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanimation.cc
More file actions
69 lines (56 loc) · 1.36 KB
/
animation.cc
File metadata and controls
69 lines (56 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <list>
#include "animation.hh"
Animation::Animation()
{
}
Animation::~Animation()
{
std::list<AnimationItem *>::iterator myitem;
for (myitem = this->items.begin(); myitem != this->items.end(); myitem++)
{
delete (*myitem);
}
}
void Animation::initialize(double start, double dur)
{
this->duration = dur;
this->startTime = start;
}
void Animation::addItem(Variable *var, double endval)
{
AnimationItem *myitem = new AnimationItem;
myitem->initialize(var, endval);
this->items.push_back(myitem);
}
int Animation::update(double currentTime)
{
std::list<AnimationItem *>::iterator myitem;
bool complete = false;
double pct_elapsed = (currentTime - this->startTime)/this->duration;
if (pct_elapsed >= 1)
{
complete = true;
pct_elapsed = 1;
}
for (myitem = this->items.begin(); myitem != this->items.end(); myitem++)
{
(*myitem)->update(pct_elapsed);
}
return complete;
}
AnimationItem::AnimationItem()
{
}
AnimationItem::~AnimationItem()
{
}
void AnimationItem::initialize(Variable *varin, double endval)
{
this->var = varin;
this->startValue = this->var->getDecimal();
this->deltaValue = endval - this->startValue;
}
void AnimationItem::update(double pct_elapsed)
{
this->var->setToDecimal(this->startValue + (pct_elapsed * this->deltaValue));
}