claw
1.9.0
Toggle main menu visibility
Loading...
Searching...
No Matches
single_tweener.cpp
1
/*
2
CLAW - a C++ Library Absolutely Wonderful
3
4
CLAW is a free library without any particular aim but being useful to
5
anyone.
6
7
Copyright (C) 2005-2011 Julien Jorge
8
9
This library is free software; you can redistribute it and/or
10
modify it under the terms of the GNU Lesser General Public
11
License as published by the Free Software Foundation; either
12
version 2.1 of the License, or (at your option) any later version.
13
14
This library is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
Lesser General Public License for more details.
18
19
You should have received a copy of the GNU Lesser General Public
20
License along with this library; if not, write to the Free Software
21
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
contact: julien.jorge@stuff-o-matic.com
23
*/
29
#include <
claw/tween/single_tweener.hpp
>
30
31
#include <algorithm>
32
36
claw::tween::single_tweener::single_tweener
()
37
: m_date(0)
38
, m_easing(
easing_none
::ease_in_out)
39
{}
40
49
claw::tween::single_tweener::single_tweener
(
double
init,
double
end,
50
double
duration,
51
update_function
callback,
52
easing_function
e)
53
: m_init(init)
54
, m_end(end)
55
, m_date(0)
56
, m_duration(duration)
57
, m_callback(callback)
58
, m_easing(e)
59
{}
60
68
claw::tween::single_tweener::single_tweener
(
double
& val,
double
end,
69
double
duration,
easing_function
e)
70
: m_init(val)
71
, m_end(end)
72
, m_date(0)
73
, m_duration(duration)
74
, m_easing(e)
75
{
76
m_callback = [&val](
double
v) ->
void
77
{
78
val = v;
79
};
80
}
81
85
double
claw::tween::single_tweener::get_init
()
const
86
{
87
return
m_init;
88
}
89
94
void
claw::tween::single_tweener::set_init
(
double
v)
95
{
96
m_init = v;
97
}
98
102
double
claw::tween::single_tweener::get_end
()
const
103
{
104
return
m_end;
105
}
106
111
void
claw::tween::single_tweener::set_end
(
double
v)
112
{
113
m_end = v;
114
}
115
119
double
claw::tween::single_tweener::get_duration
()
const
120
{
121
return
m_duration;
122
}
123
128
void
claw::tween::single_tweener::set_duration
(
double
v)
129
{
130
m_duration = v;
131
}
132
137
void
claw::tween::single_tweener::set_callback
(
update_function
f)
138
{
139
m_callback = f;
140
}
141
146
void
claw::tween::single_tweener::set_easing
(
easing_function
f)
147
{
148
m_easing = f;
149
}
150
154
double
claw::tween::single_tweener::get_value
()
const
155
{
156
const
double
coeff = m_easing(m_date / m_duration);
157
return
m_init + coeff * (m_end - m_init);
158
}
159
163
claw::tween::single_tweener
* claw::tween::single_tweener::do_clone()
const
164
{
165
return
new
single_tweener
(*
this
);
166
}
167
171
bool
claw::tween::single_tweener::do_is_finished()
const
172
{
173
return
m_date >= m_duration;
174
}
175
180
double
claw::tween::single_tweener::do_update(
double
dt)
181
{
182
const
double
t(std::min(m_duration - m_date, dt));
183
const
double
result = dt - t;
184
m_date += t;
185
186
const
double
val(get_value());
187
188
if
(m_callback)
189
m_callback(val);
190
191
return
result;
192
}
claw::tween::easing_none
Easing functions for the tweener. Those functions do nothing.
Definition
easing_none.hpp:41
claw::tween::single_tweener
A single_tweener makes a value to evolve through time from a initial value to an end value according ...
Definition
single_tweener.hpp:49
claw::tween::single_tweener::set_duration
void set_duration(double v)
Sets the total duration.
Definition
single_tweener.cpp:128
claw::tween::single_tweener::get_end
double get_end() const
Gets the final value.
Definition
single_tweener.cpp:102
claw::tween::single_tweener::set_end
void set_end(double v)
Sets the final value.
Definition
single_tweener.cpp:111
claw::tween::single_tweener::single_tweener
single_tweener()
Default constructor.
Definition
single_tweener.cpp:36
claw::tween::single_tweener::set_easing
void set_easing(easing_function f)
The function used to compute the new value.
Definition
single_tweener.cpp:146
claw::tween::single_tweener::easing_function
std::function< double(double)> easing_function
The type of the function used to compute the new value.
Definition
single_tweener.hpp:56
claw::tween::single_tweener::get_init
double get_init() const
Gets the initial value.
Definition
single_tweener.cpp:85
claw::tween::single_tweener::set_init
void set_init(double v)
Sets the initial value.
Definition
single_tweener.cpp:94
claw::tween::single_tweener::get_duration
double get_duration() const
Gets the total duration.
Definition
single_tweener.cpp:119
claw::tween::single_tweener::set_callback
void set_callback(update_function f)
The function called when the single_tweener is updated.
Definition
single_tweener.cpp:137
claw::tween::single_tweener::get_value
double get_value() const
Gets the current value of the tweener.
Definition
single_tweener.cpp:154
claw::tween::single_tweener::update_function
std::function< void(double)> update_function
The type of the function called when the single_tweener is updated.
Definition
single_tweener.hpp:53
single_tweener.hpp
A single_tweener makes a value to evolve through time from a initial value to an end value according ...
lib
tween
src
claw
tween
single_tweener.cpp
Generated by
1.17.0