Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template <typename value_type, typename curve_type>
- func value_type get_value_from_curve(float percent, value_type default_value, s_sarray<curve_type, 8> curve)
- {
- m_timed_function();
- curve_type left = zero;
- curve_type right = zero;
- if(curve.count == 0) {
- left = zero;
- left.value = default_value;
- right = left;
- }
- else if(curve.count == 1) {
- left = curve[0];
- right = left;
- }
- else {
- for(int point_i = 0; point_i < curve.count - 1; point_i++) {
- auto a = curve[point_i];
- auto b = curve[point_i + 1];
- if(percent >= a.percent && percent <= b.percent) {
- left = a;
- right = b;
- }
- }
- }
- value_type left_value = left.value;
- value_type right_value = right.value;
- float bar = ilerp(left.percent, right.percent, percent);
- switch(left.curve_type) {
- case e_curve_type_linear: {
- } break;
- case e_curve_type_ease_in: {
- bar = powf(bar, 4);
- } break;
- case e_curve_type_ease_out: {
- bar = powf(bar, 0.25f);
- } break;
- case e_curve_type_instant: {
- bar = 0;
- } break;
- invalid_default_case;
- }
- return lerp(left_value, right_value, bar);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement