5#include <glm/gtx/easing.hpp>
13 concept CurveValueConcept =
requires(T t)
15 {0.5f * t} -> std::convertible_to<T>;
16 {t + t} -> std::convertible_to<T>;
25 {t} -> std::convertible_to<float>;
31 template <
typename T,
typename V,
typename P>
34 {t.value} -> std::convertible_to<V>;
35 {t.position} -> std::convertible_to<P>;
52 template <CurveValueConcept V, CurvePositionConcept P =
float>
85 return begin_point.value;
89 return end_point.value;
92 P factor = (end_point.position != begin_point.position)
93 ? (ratio - begin_point.position) / (end_point.position - begin_point.position)
99 factor = glm::cubicEaseInOut(factor);
102 return glm::mix(begin_point.value, end_point.value, factor);
118 template<CurveValueConcept V, CurvePositionConcept T>
129 template <
typename Type>
156 template <CurveValueConcept V, CurvePositionConcept T =
float,
typename CurveSettingsType = CurveSettings>
160 using ContainerType =
typename CurveSettingsType::template PointStorageType<PointType>;
176 [[nodiscard]]
constexpr V
eval(
const T x)
const noexcept
192 return point.position > x;
198 return pos_final->value;
204 return (pos_final-1)->value;
207 const auto pos_begin = pos_final-1;
209 return PointType::interpolate(*pos_begin, *pos_final, x);
Curve point (= keyframe) must have value and position members.
Definition curve.h:32
Curve point position (= abscissa) must be convertible to a floating point value.
Definition curve.h:23
Various utilities.
Definition node.h:15
CurveInterpolation
Interpolation mode between points.
Definition curve.h:42
@ 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:54
CurveInterpolation interpolation
How to interpolate between last point and this point.
Definition curve.h:57
static constexpr V interpolate(const CurvePoint &begin_point, const CurvePoint &end_point, const P ratio) noexcept
Interpolate Value between two points.
Definition curve.h:81
V value
Value of this point.
Definition curve.h:56
P position
Position of this point on the curve.
Definition curve.h:55
constexpr auto operator<=>(const CurvePoint &other) const
Three-way comparison operator.
Definition curve.h:67
Curve Advanced settings.
Definition curve.h:112
std::vector< Type > PointStorageType
The container to use to store points of the curve.
Definition curve.h:130
General purpose curve (can be used for color gradients, animations, etc...)
Definition curve.h:158
ContainerType control_points
Points of the curve.
Definition curve.h:212
typename CurveSettingsType::template PointStorageType< PointType > ContainerType
Type used to store all points.
Definition curve.h:160
constexpr V eval(const T x) const noexcept
Compute a value on the curve based on its control points.
Definition curve.h:176
typename CurveSettingsType::template PointType< V, T > PointType
Type used as a point on the curve.
Definition curve.h:159