Dawn/archive/animation/easing.cpp

66 lines
1.3 KiB
C++

// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "easing.hpp"
float_t easeTimeToEase(
const float_t start,
const float_t current,
const float_t duration
) {
return (current - start) / duration;
}
float_t easeLinear(const float_t t) {
return t;
}
float_t easeInQuad(const float_t t) {
return t * t;
}
float_t easeOutQuad(const float_t t) {
return t * (2 - t);
}
float_t easeOutCubic(const float_t t) {
return 1 - powf(1 - t, 3);
}
float_t easeInOutQuad(const float_t t) {
return t < .5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
}
float_t easeInCubic(const float_t t) {
return t * t * t;
}
float_t easeInOutCubic(const float_t t) {
return t < .5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1;
}
float_t easeInQuart(const float_t t) {
return t * t * t * t;
}
float_t easeOutQuart(const float_t t) {
return 1 - (t-1)*(t-1)*(t-1)*(t-1);
}
float_t easeInOutQuart(const float_t t) {
return t < .5 ? 8*t*t*t*t : 1-8*(t-1)*(t-1)*(t-1)*(t-1);
}
float_t easeInQuint(const float_t t) {
return t*t*t*t*t;
}
float_t easeOutQuint(const float_t t) {
return 1 + (t-1)*(t-1)*(t-1)*(t-1)*(t-1);
}
float_t easeInOutQuint(const float_t t) {
return t<.5 ? 16*t*t*t*t*t : 1+16*(t-1)*(t-1)*(t-1)*(t-1)*(t-1);
}