Unravel Engine C++ Reference
Loading...
Searching...
No Matches
seq_math.hpp
Go to the documentation of this file.
1#pragma once
2#include "seq_math.h"
3
4namespace seq
5{
6
7template<typename T>
8auto lerp(const T& start, const T& end, float progress, const ease_t& ease_func) -> T
9{
10 if(progress <= 0.0f)
11 {
12 return start;
13 }
14
15 if(progress >= 1.0f)
16 {
17 return end;
18 }
19
20 auto completion = ease_func(progress);
21 return start * (1.0f - completion) + (end * completion);
22}
23
24template<typename InType, typename OutType>
25auto range_map(const InType& in,
26 const decltype(in)& in_start,
27 const decltype(in)& in_end,
28 const OutType& out_start,
29 const decltype(out_start)& out_end,
30 const ease_t& ease_func) -> OutType
31{
32 if(in <= in_start)
33 {
34 return out_start;
35 }
36
37 if(in >= in_end)
38 {
39 return out_end;
40 }
41
42 auto progress = in - in_start;
43 auto in_factor = static_cast<float>(progress) / static_cast<float>(in_end - in_start);
44 OutType result = lerp(out_start, out_end, in_factor, ease_func);
45 return result;
46}
47
48} // namespace seq
Provides a sequence-based action management system for controlling and scheduling actions.
auto start(seq_action action, const seq_scope_policy &scope_policy, hpp::source_location location) -> seq_id_t
Starts a new action.
Definition seq.cpp:8
std::function< float(float)> ease_t
Represents an easing function for interpolation.
Definition seq_common.h:61
auto lerp(const T &start, const T &end, float progress, const ease_t &ease_func=ease::linear) -> T
Linearly interpolates between two values based on progress.
Definition seq_math.hpp:8
auto range_map(const InType &in, const decltype(in)&in_start, const decltype(in)&in_end, const OutType &out_start, const decltype(out_start)&out_end, const ease_t &ease_func=ease::linear) -> OutType
Maps a value from one range to another range, with optional easing.
Definition seq_math.hpp:25