4#include <glm/gtx/easing.hpp>
14 {0.5f * t} -> std::convertible_to<T>;
15 {t + t} -> std::convertible_to<T>;
24 {t} -> std::convertible_to<float>;
30 template <
typename T,
typename V,
typename P>
33 {t.value} -> std::convertible_to<V>;
34 {t.position} -> std::convertible_to<P>;
51 template <CurveValueConcept V, CurvePositionConcept P =
float>
84 return begin_point.value;
88 return end_point.value;
91 P factor = (end_point.position != begin_point.position)
92 ? (ratio - begin_point.position) / (end_point.position - begin_point.position)
98 factor = glm::cubicEaseInOut(factor);
101 return glm::mix(begin_point.value, end_point.value, factor);
117 template<CurveValueConcept V, CurvePositionConcept T>
128 template <
typename Type>
155 template <CurveValueConcept V, CurvePositionConcept T =
float,
typename CurveSettingsType = CurveSettings>
158 using PointType =
typename CurveSettingsType::PointType<V, T>;
159 using ContainerType =
typename CurveSettingsType::PointStorageType<PointType>;
175 [[nodiscard]]
constexpr V
eval(
const T x)
const noexcept
191 return point.position > x;
197 return pos_final->value;
203 return (pos_final-1)->value;
206 const auto pos_begin = pos_final-1;
208 return PointType::interpolate(*pos_begin, *pos_final, x);
Curve point (= keyframe) must have value and position members.
Definition curve.h:31
Curve point position (= abscissa) must be convertible to a floating point value.
Definition curve.h:22
Curve point value type must overloads operators "addition between objects" and "multiplication with a...
Definition curve.h:12
Various utilities.
Definition byte_array.h:20
CurveInterpolation
Interpolation mode between points.
Definition curve.h:41
@ HOLD_LAST
Hold last value.
@ DIRECT
No interpolation, directly switch to this value.
@ LINEAR
Do a linear interpolation between last value and this one.
@ CUBIC
Do a cubic interpolation between last value and this one.
Point on a curve, also called a keyframe in some contexts.
Definition curve.h:53
CurveInterpolation interpolation
How to interpolate between last point and this point.
Definition curve.h:56
static constexpr V interpolate(const CurvePoint &begin_point, const CurvePoint &end_point, const P ratio) noexcept
Interpolate Value between two points.
Definition curve.h:80
V value
Value of this point.
Definition curve.h:55
P position
Position of this point on the curve.
Definition curve.h:54
constexpr auto operator<=>(const CurvePoint &other) const
Three-way comparison operator.
Definition curve.h:66
Curve Advanced settings.
Definition curve.h:111
std::vector< Type > PointStorageType
The container to use to store points of the curve.
Definition curve.h:129
General purpose curve (can be used for color gradients, animations, etc...)
Definition curve.h:157
ContainerType control_points
Points of the curve.
Definition curve.h:211
typename CurveSettingsType::PointStorageType< PointType > ContainerType
Type used to store all points.
Definition curve.h:159
typename CurveSettingsType::PointType< V, T > PointType
Type used as a point on the curve.
Definition curve.h:158
constexpr V eval(const T x) const noexcept
Compute a value on the curve based on its control points.
Definition curve.h:175