-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathanimator.cpp
More file actions
60 lines (54 loc) · 1.86 KB
/
Copy pathanimator.cpp
File metadata and controls
60 lines (54 loc) · 1.86 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
#include "animator.h"
#include "timer.h"
fr::Animator *fr::Animator::m_instance = 0;
void fr::Animator::AddAnimation(std::string id, AnimationType type, int duration)
{
Animation *new_animation = new Animation;
new_animation->type = type;
new_animation->duration = duration;
m_anim[id] = new_animation;
}
void fr::Animator::Animate(std::string id)
{
Timer::instance()->RunTimer(std::string("animation_") + id);
}
void fr::Animator::ResetAnimation(std::string id)
{
Timer::instance()->ResetTimer(std::string("animation_") + id);
}
float fr::Animator::GetProcess(std::string id)
{
float output = 0;
if (!IsTimeUp(id))
{
switch (m_anim[id]->type)
{
case ANIMATIONTYPE_UNIFORMLY_ACCELERATED:
output = float(Timer::instance()->GetTime(std::string("animation_") + id) * Timer::instance()->GetTime(std::string("animation_") + id)) / float(m_anim[id]->duration * m_anim[id]->duration);
break;
case ANIMATIONTYPE_UNIFORMLY_DECELERATED:
/*
a = 2 / T^2
s = 2 / T * t + T^2 * (t ^ 2)
= (2 * 2 / T - 2 / T^2 * t) / 2 * t
vt = v0 - at = 0
v0 = aT
s = (2 * (2 * straight / T^2) * T - (straight / T^2) * t) / 2 * t
= (4 * straight / T - straight / T^2 * t) / 2 * t
= (2 * straight / T - 0.5 * straight / T^2 *t) * t
*/
output = (2.f / m_anim[id]->duration - 1.f / m_anim[id]->duration / m_anim[id]->duration * Timer::instance()->GetTime(std::string("animation_") + id)) * float(Timer::instance()->GetTime(std::string("animation_") + id));
// output = float(Timer::instance()->GetTime(std::string("animation_") + id) * Timer::instance()->GetTime(std::string("animation_") + id)) / float(m_anim[id]->duration * m_anim[id]->duration);
break;
}
}
else
{
output = 1;
}
return output;
}
bool fr::Animator::IsTimeUp(std::string id)
{
return Timer::instance()->GetTime(std::string("animation_") + id) > m_anim[id]->duration;
}