11template <
typename Type,
typename PayloadT>
12concept SamplerT =
requires(Type
const& t, std::span<Keyframe<PayloadT>
const> keyframes, kvf::Seconds time) {
13 { t.sample(keyframes, time) } -> std::same_as<PayloadT>;
17template <
typename PayloadT>
19 [[nodiscard]]
constexpr auto sample(std::span<
Keyframe<PayloadT> const> keyframes, kvf::Seconds
const time)
const -> PayloadT {
20 if (keyframes.empty()) {
return {}; }
21 auto const it = std::ranges::upper_bound(keyframes, time, {}, [](
Keyframe<PayloadT> const& kf) {
return kf.timestamp; });
22 if (it == keyframes.end()) {
return keyframes.back().payload; }
23 if (it == keyframes.begin()) {
return it->payload; }
24 return (it - 1)->payload;
29template <
typename PayloadT,
typename InterpolatorT = Interpolator<PayloadT>>
31 [[nodiscard]]
constexpr auto sample(std::span<
Keyframe<PayloadT> const> keyframes, kvf::Seconds
const time)
const -> PayloadT {
32 if (keyframes.empty()) {
return {}; }
33 auto const it = std::ranges::upper_bound(keyframes, time, {}, [](
Keyframe<PayloadT> const& kf) {
return kf.timestamp; });
34 if (it == keyframes.begin()) {
return it->payload; }
35 if (it == keyframes.end()) {
return (it - 1)->payload; }
36 auto const& a = *(it - 1);
38 auto const total_t = b.timestamp - a.timestamp;
39 auto const t = (time - a.timestamp) / total_t;
40 return InterpolatorT{}(a.payload, b.payload, t);
Concept for Animation Sampler.
Definition sampler.hpp:12
Definition animation.hpp:9
Class template for an animation keyframe.
Definition keyframe.hpp:7
Quantized Animation Sampler.
Definition sampler.hpp:18
constexpr auto sample(std::span< Keyframe< PayloadT > const > keyframes, kvf::Seconds const time) const -> PayloadT
Definition sampler.hpp:19
Interpolation Animation Sampler.
Definition sampler.hpp:30
constexpr auto sample(std::span< Keyframe< PayloadT > const > keyframes, kvf::Seconds const time) const -> PayloadT
Definition sampler.hpp:31