le2d v0.4.3
2D game engine framework
 
Loading...
Searching...
No Matches
interpolator.hpp
Go to the documentation of this file.
1#pragma once
2#include <glm/common.hpp>
3#include <le2d/transform.hpp>
4#include <cmath>
5
6namespace le::anim {
7template <typename Type>
8struct Interpolator;
9
11template <typename Type>
12constexpr auto interpolate(Type const& a, Type const& b, float const t) {
13 return Interpolator<Type>{}(a, b, t);
14}
15
17template <typename Type>
19 constexpr auto operator()(Type const& a, Type const& b, float const t) const { return std::lerp(a, b, t); }
20};
21
23template <typename Type, glm::length_t Length>
24struct Interpolator<glm::vec<Length, Type>> {
25 constexpr auto operator()(glm::vec<Length, Type> const a, glm::vec<Length, Type> const b, float const t) const { return glm::mix(a, b, t); }
26};
27
29template <>
31 auto operator()(Transform const& a, Transform const& b, float const t) const {
32 return Transform{
34 .orientation = nvec2::from_radians(interpolate(a.orientation.to_radians(), b.orientation.to_radians(), t)),
35 .scale = interpolate(a.scale, b.scale, t),
36 };
37 }
38};
39} // namespace le::anim
auto to_radians() const -> float
Definition animation.hpp:9
constexpr auto interpolate(Type const &a, Type const &b, float const t)
Wrapper for Interpolator<Type>{}(a, b, t).
Definition interpolator.hpp:12
2D transformation.
Definition transform.hpp:8
glm::vec2 position
Definition transform.hpp:21
nvec2 orientation
Definition transform.hpp:22
glm::vec2 scale
Definition transform.hpp:23
auto operator()(Transform const &a, Transform const &b, float const t) const
Definition interpolator.hpp:31
constexpr auto operator()(glm::vec< Length, Type > const a, glm::vec< Length, Type > const b, float const t) const
Definition interpolator.hpp:25
Base class template for linear interpolation.
Definition interpolator.hpp:18
constexpr auto operator()(Type const &a, Type const &b, float const t) const
Definition interpolator.hpp:19