easing functions
parent
a3e187bd01
commit
a8b2bc2d01
|
@ -1,7 +1,7 @@
|
||||||
cmake_minimum_required(VERSION 3.20)
|
cmake_minimum_required(VERSION 3.20)
|
||||||
include(cmake/color.cmake)
|
include(cmake/color.cmake)
|
||||||
|
|
||||||
set(BLT_VERSION 0.17.9)
|
set(BLT_VERSION 0.17.10)
|
||||||
set(BLT_TEST_VERSION 0.0.1)
|
set(BLT_TEST_VERSION 0.0.1)
|
||||||
|
|
||||||
set(BLT_TARGET BLT)
|
set(BLT_TARGET BLT)
|
||||||
|
|
|
@ -0,0 +1,109 @@
|
||||||
|
#pragma once
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2024 Brett Terpstra
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BLT_INTERPOLATION_H
|
||||||
|
#define BLT_INTERPOLATION_H
|
||||||
|
|
||||||
|
#include "vectors.h"
|
||||||
|
|
||||||
|
namespace blt
|
||||||
|
{
|
||||||
|
inline constexpr color4 linear_interpolate(const color4& in, const color4& desired, float factor)
|
||||||
|
{
|
||||||
|
auto diff = desired - in;
|
||||||
|
return in + (diff * factor);
|
||||||
|
}
|
||||||
|
|
||||||
|
class easing_function
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
easing_function() = default;
|
||||||
|
|
||||||
|
virtual color4 apply(const color4& start, const color4& end) = 0;
|
||||||
|
|
||||||
|
void progress(float progress)
|
||||||
|
{
|
||||||
|
total_progress += progress;
|
||||||
|
}
|
||||||
|
|
||||||
|
void reset()
|
||||||
|
{
|
||||||
|
total_progress = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
float x()
|
||||||
|
{
|
||||||
|
return total_progress;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
float total_progress = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
class quad_easing : public easing_function
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
color4 apply(const color4& start, const color4& end) final
|
||||||
|
{
|
||||||
|
if (x() >= 1)
|
||||||
|
return end;
|
||||||
|
auto diff = end - start;
|
||||||
|
return start + (diff * (x() * x()));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class cubic_easing : public easing_function
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
color4 apply(const color4& start, const color4& end) final
|
||||||
|
{
|
||||||
|
if (x() >= 1)
|
||||||
|
return end;
|
||||||
|
auto diff = end - start;
|
||||||
|
return start + (diff * (x() * x() * x()));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class quart_easing : public easing_function
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
color4 apply(const color4& start, const color4& end) final
|
||||||
|
{
|
||||||
|
if (x() >= 1)
|
||||||
|
return end;
|
||||||
|
auto diff = end - start;
|
||||||
|
return start + (diff * (x() * x() * x() * x()));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class quint_easing : public easing_function
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
color4 apply(const color4& start, const color4& end) final
|
||||||
|
{
|
||||||
|
if (x() >= 1)
|
||||||
|
return end;
|
||||||
|
auto diff = end - start;
|
||||||
|
return start + (diff * (x() * x() * x() * x() * x()));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //BLT_INTERPOLATION_H
|
|
@ -433,12 +433,6 @@ namespace blt
|
||||||
using color4 = vec4;
|
using color4 = vec4;
|
||||||
using color3 = vec3;
|
using color3 = vec3;
|
||||||
|
|
||||||
inline constexpr color4 interpolate(const color4& in, const color4& desired, float factor)
|
|
||||||
{
|
|
||||||
auto diff = desired - in;
|
|
||||||
return in + (diff * factor);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline constexpr color4 make_color(float r, float g, float b)
|
inline constexpr color4 make_color(float r, float g, float b)
|
||||||
{
|
{
|
||||||
return color4{r, g, b, 1.0f};
|
return color4{r, g, b, 1.0f};
|
||||||
|
|
Loading…
Reference in New Issue