animacions a renderinfo
This commit is contained in:
24
source/utils/easing.cpp
Normal file
24
source/utils/easing.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#include "utils/easing.hpp"
|
||||
|
||||
namespace Easing {
|
||||
|
||||
auto linear(float t) -> float { return t; }
|
||||
|
||||
auto outQuad(float t) -> float { return 1.0F - (1.0F - t) * (1.0F - t); }
|
||||
auto inQuad(float t) -> float { return t * t; }
|
||||
auto inOutQuad(float t) -> float {
|
||||
return t < 0.5F ? 2.0F * t * t : 1.0F - (-2.0F * t + 2.0F) * (-2.0F * t + 2.0F) / 2.0F;
|
||||
}
|
||||
|
||||
auto outCubic(float t) -> float {
|
||||
const float inv = 1.0F - t;
|
||||
return 1.0F - inv * inv * inv;
|
||||
}
|
||||
auto inCubic(float t) -> float { return t * t * t; }
|
||||
|
||||
auto lerp(float a, float b, float t) -> float { return a + (b - a) * t; }
|
||||
auto lerpInt(int a, int b, float t) -> int {
|
||||
return a + static_cast<int>((b - a) * t);
|
||||
}
|
||||
|
||||
} // namespace Easing
|
||||
22
source/utils/easing.hpp
Normal file
22
source/utils/easing.hpp
Normal file
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
// Funcions de suavitzat per animacions. Totes accepten t en el rang [0, 1]
|
||||
// i retornen un valor en [0, 1] (amb overshoot possible en algunes variants).
|
||||
namespace Easing {
|
||||
|
||||
auto linear(float t) -> float;
|
||||
|
||||
// Quadratic
|
||||
auto outQuad(float t) -> float;
|
||||
auto inQuad(float t) -> float;
|
||||
auto inOutQuad(float t) -> float;
|
||||
|
||||
// Cubic
|
||||
auto outCubic(float t) -> float;
|
||||
auto inCubic(float t) -> float;
|
||||
|
||||
// Interpolacions (aplicar després d'un easing al paràmetre t)
|
||||
auto lerp(float a, float b, float t) -> float;
|
||||
auto lerpInt(int a, int b, float t) -> int;
|
||||
|
||||
} // namespace Easing
|
||||
Reference in New Issue
Block a user