20 #ifndef ANTKEEPER_TWEEN_HPP
21 #define ANTKEEPER_TWEEN_HPP
26 #include <type_traits>
34 template <
class T,
class S =
float>
38 static_assert(std::is_scalar<S>::value);
121 template <
class T,
class S>
124 throw std::runtime_error(
"tween interpolator not set");
127 template <
class T,
class S>
129 states{value, value},
130 interpolator(interpolator)
133 template <
class T,
class S>
135 states{state0, state1},
136 interpolator(interpolator)
139 template <
class T,
class S>
141 interpolator(nullptr)
144 template <
class T,
class S>
150 template <
class T,
class S>
156 template <
class T,
class S>
159 return interpolate(a);
162 template <
class T,
class S>
165 return interpolator(states[0], states[1], a);
168 template <
class T,
class S>
171 this->interpolator = interpolator;
174 template <
class T,
class S>
180 template <
class T,
class S>
183 states[0] = states[1];
186 template <
class T,
class S>
189 std::swap(states[0], states[1]);
Container which stores two states along with an interpolator, for quick and easy tween<T,...
void update()
Sets state 0 = state 1.
tween(const value_type &state0, const value_type &state1, interpolator_type interpolator=tween< T, S >::interpolator_error)
Creates a tween.
std::decay< std::function< value_type(const value_type &, const value_type &, scalar_type)> >::type interpolator_type
value_type interpolate(scalar_type a) const
Returns an interpolated state between state 0 and state 1.
value_type operator[](scalar_type a) const
S>::interpolate(scalar_type) const
void swap()
Swaps state 0 and state 1.
tween(const value_type &value, interpolator_type interpolator=tween< T, S >::interpolator_error)
Creates a tween.
void set_interpolator(const interpolator_type &interpolator)
Sets the function used to interpolate between states 0 and 1.
const interpolator_type & get_interpolator() const
Returns the function used to interpolate between states 0 and 1.
value_type & operator[](int i)
S>::operator[](int) const
const value_type & operator[](int i) const
Returns a reference to the specified tween state.