Color: afegit metode LERP()
This commit is contained in:
@@ -95,6 +95,29 @@ struct Color {
|
|||||||
return Color(new_r, new_g, new_b, new_a);
|
return Color(new_r, new_g, new_b, new_a);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Interpolación lineal hacia otro color (t=0.0: this, t=1.0: target)
|
||||||
|
[[nodiscard]] constexpr auto LERP(const Color &target, float t) const -> Color {
|
||||||
|
// Asegurar que t esté en el rango [0.0, 1.0]
|
||||||
|
t = std::clamp(t, 0.0f, 1.0f);
|
||||||
|
|
||||||
|
// Interpolación lineal para cada componente
|
||||||
|
auto lerp_component = [t](Uint8 start, Uint8 end) -> Uint8 {
|
||||||
|
return static_cast<Uint8>(start + (end - start) * t);
|
||||||
|
};
|
||||||
|
|
||||||
|
return Color(
|
||||||
|
lerp_component(r, target.r),
|
||||||
|
lerp_component(g, target.g),
|
||||||
|
lerp_component(b, target.b),
|
||||||
|
lerp_component(a, target.a)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sobrecarga para aceptar componentes RGBA directamente
|
||||||
|
[[nodiscard]] constexpr auto LERP(Uint8 red, Uint8 green, Uint8 blue, Uint8 alpha, float t) const -> Color {
|
||||||
|
return LERP(Color(red, green, blue, alpha), t);
|
||||||
|
}
|
||||||
|
|
||||||
// Convierte el color a un entero de 32 bits en formato RGBA
|
// Convierte el color a un entero de 32 bits en formato RGBA
|
||||||
[[nodiscard]] constexpr auto TO_UINT32() const -> Uint32 {
|
[[nodiscard]] constexpr auto TO_UINT32() const -> Uint32 {
|
||||||
return (static_cast<Uint32>(r) << 24) |
|
return (static_cast<Uint32>(r) << 24) |
|
||||||
|
|||||||
Reference in New Issue
Block a user