-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzglInterpolator.cpp
executable file
·130 lines (112 loc) · 3.25 KB
/
zglInterpolator.cpp
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
* Copyright (C) 2010 ZiiLABS Pte Ltd
* All Rights Reserved.
*
* This software and its associated documentation may contain some
* proprietary, confidential and trade secret information of
* ZiiLABS Pte Ltd and except as provided by written agreement with
* ZiiLABS Pte Ltd
*
* a) no part may be disclosed, distributed, reproduced, transmitted,
* transcribed, stored in a retrieval system, adapted or translated
* in any form or by any means electronic, mechanical, magnetic,
* optical, chemical, manual or otherwise,
*
* and
*
* b) the recipient is not entitled to discover through reverse
* engineering or reverse compiling or other such techniques or
* processes the trade secrets contained therein or in the
* documentation.
*/
#include <math.h>
#include "zglInterpolator.h"
#include "zglBasicType.h"
//!< --------------------------------------------------------------------------
float zglInterpolator::getValue(float t)
{
return t;
}
//!< --------------------------------------------------------------------------
float zglLinearInterpolator::getValue(float t)
{
return t;
}
//!< --------------------------------------------------------------------------
float zglAccelerateInterpolator::getValue(float t)
{
if (m_factor == 1.0f)
{
return t * t;
}
else
{
return (float) pow(t, m_factor * 2);
}
}
//!< --------------------------------------------------------------------------
float zglDecelerateInterpolator::getValue(float t)
{
if (m_factor == 1.0f)
{
return (float) (1.0f - (1.0f - t) * (1.0f - t));
}
else
{
return (float) (1.0f - pow((1.0f - t), m_factor * 2.0f));
}
}
//!< --------------------------------------------------------------------------
float zglAccelerateDecelerateInterpolator::getValue(float t)
{
return (float) (cos((t + 1) * ZGL_PI) / 2.0f) + 0.5f;
}
//!< --------------------------------------------------------------------------
float zglAnticipateInterpolator::getValue(float t)
{
return t * t * ((m_tension + 1) * t - m_tension);
}
//!< --------------------------------------------------------------------------
float zglAnticipateOvershootInterpolator::getValue(float t)
{
if (t < 0.5f)
return 0.5f * a(t * 2.0f, m_tension);
else
return 0.5f * (o(t * 2.0f - 2.0f, m_tension) + 2.0f);
}
float zglAnticipateOvershootInterpolator::a(float t, float s)
{
return t * t * ((s + 1) * t - s);
}
float zglAnticipateOvershootInterpolator::o(float t, float s)
{
return t * t * ((s + 1) * t + s);
}
//!< --------------------------------------------------------------------------
float zglBounceInterpolator::getValue(float t)
{
t *= 1.1226f;
if (t < 0.3535f)
return bounce(t);
else if (t < 0.7408f)
return bounce(t - 0.54719f) + 0.7f;
else if (t < 0.9644f)
return bounce(t - 0.8526f) + 0.9f;
else
return bounce(t - 1.0435f) + 0.95f;
}
float zglBounceInterpolator::bounce(float t)
{
return t * t * 0.8f;
}
//!< --------------------------------------------------------------------------
float zglCycleInterpolator::getValue(float t)
{
return (float) sin(2 * m_cycle * t * ZGL_PI);
}
//!< --------------------------------------------------------------------------
float zglOvershootInterpolator::getValue(float t)
{
t -= 1.0f;
return t * t * ((m_tension + 1) * t + m_tension) + 1.0f;
}