#include "headers/animation.hpp" namespace asloengine { Animation::Animation(Function _function, float _start_value, float _end_value, float _duration) { reset(_function, _start_value, _end_value, _duration); } void Animation::reset(Function _function, float _start_value, float _end_value, float _duration) { function = _function; start_value = _start_value; current_value = _start_value; end_value = _end_value; time = 0; duration = _duration; } float Animation::animate(float delta_time) { time += delta_time; if (time > duration) { time = duration; } switch (function) { case LINEAR: return calculate_linear(); case EASE_IN: return calculate_ease_in(); case EASE_OUT: return calculate_ease_out(); case EASE_IN_OUT: return calculate_ease_in_out(); } return 0; } float Animation::calculate_linear() { float value_difference = end_value - start_value; float progress = time / duration; return start_value + value_difference * progress; } float Animation::calculate_ease_in() { // TO-DO return 0; } float Animation::calculate_ease_out() { // TO-DO return 0; } float Animation::calculate_ease_in_out() { float value_difference = end_value - start_value; float progress = time / duration; progress = pow(progress, 2) / (pow(progress, 2) + pow((1 - progress), 2)); return (start_value + value_difference * progress); } }