Advertisement
Tkap1

Untitled

Dec 3rd, 2023
896
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. template <typename value_type, typename curve_type>
  2. func value_type get_value_from_curve(float percent, value_type default_value, s_sarray<curve_type, 8> curve)
  3. {
  4.     m_timed_function();
  5.     curve_type left = zero;
  6.     curve_type right = zero;
  7.     if(curve.count == 0) {
  8.         left = zero;
  9.         left.value = default_value;
  10.         right = left;
  11.     }
  12.     else if(curve.count == 1) {
  13.         left = curve[0];
  14.         right = left;
  15.     }
  16.     else {
  17.         for(int point_i = 0; point_i < curve.count - 1; point_i++) {
  18.             auto a = curve[point_i];
  19.             auto b = curve[point_i + 1];
  20.             if(percent >= a.percent && percent <= b.percent) {
  21.                 left = a;
  22.                 right = b;
  23.             }
  24.         }
  25.     }
  26.     value_type left_value = left.value;
  27.     value_type right_value = right.value;
  28.  
  29.     float bar = ilerp(left.percent, right.percent, percent);
  30.     switch(left.curve_type) {
  31.         case e_curve_type_linear: {
  32.  
  33.         } break;
  34.         case e_curve_type_ease_in: {
  35.             bar = powf(bar, 4);
  36.         } break;
  37.         case e_curve_type_ease_out: {
  38.             bar = powf(bar, 0.25f);
  39.         } break;
  40.         case e_curve_type_instant: {
  41.             bar = 0;
  42.         } break;
  43.  
  44.         invalid_default_case;
  45.     }
  46.  
  47.     return lerp(left_value, right_value, bar);
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement