Compare commits

..

No commits in common. "df950a1139a23ebe252f37cf2ac4247f3aeaa0af" and "638b16a51cb63ad13304e37de01f3e1fea8e7c57" have entirely different histories.

3 changed files with 186 additions and 357 deletions

View File

@ -14,11 +14,7 @@ option(PANDA_INCLUDE_IMGUI "include imgui" ON)
### Fallback link ### Fallback link
if(NOT RAYLIB_LINK) if(NOT RAYLIB_LINK)
set(RAYLIB_LINK "https://github.com/raysan5/raylib/archive/refs/tags/5.5.tar.gz") set(RAYLIB_LINK "https://github.com/raysan5/raylib/archive/refs/tags/5.0.zip")
endif()
if(NOT RAYLIB_EXTRA_LINK)
set(RAYLIB_EXTRA_LINK "https://github.com/raylib-extras/extras-cpp/archive/refs/heads/main.zip")
endif() endif()
if(NOT IMGUI_LINK) if(NOT IMGUI_LINK)
@ -41,10 +37,6 @@ set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
FetchContent_Declare(raylib URL ${RAYLIB_LINK}) FetchContent_Declare(raylib URL ${RAYLIB_LINK})
FetchContent_MakeAvailable(raylib) FetchContent_MakeAvailable(raylib)
message(STATUS "Downloading raylib extra library")
FetchContent_Declare(raylib-extra URL ${RAYLIB_EXTRA_LINK})
FetchContent_MakeAvailable(raylib-extra)
message(STATUS "Downloading inifile-cpp library") message(STATUS "Downloading inifile-cpp library")
FetchContent_Declare(inifile-cpp URL ${INIFILE_LINK}) FetchContent_Declare(inifile-cpp URL ${INIFILE_LINK})
FetchContent_MakeAvailable(inifile-cpp) FetchContent_MakeAvailable(inifile-cpp)
@ -55,8 +47,7 @@ file(GLOB_RECURSE PROJECT_SOURCES CONFIGURE_DEPENDS "src/*.cpp")
set(PROJECT_INCLUDE set(PROJECT_INCLUDE
"src" "src"
"${inifile-cpp_SOURCE_DIR}/include" ${inifile-cpp_SOURCE_DIR}/include)
"${raylib-extra_SOURCE_DIR}")
set(PROJECT_LIBRARY raylib) set(PROJECT_LIBRARY raylib)

View File

@ -1,307 +1,172 @@
#include <math.h>
#include "utils/Easing.hpp" #include "utils/Easing.hpp"
#include <cmath>
namespace cur = easing;
namespace easing { #ifndef PI
// Modeled after the line y = x #define PI 3.1415926545
EASING_TYPE LinearInterpolation(EASING_TYPE p) #endif
{
return p; double cur::inSine(double t) {
return sin(1.5707963 * t);
}
double cur::outSine(double t) {
return 1 + sin(1.5707963 * (--t));
}
double cur::inOutSine(double t) {
return 0.5 * (1 + sin(3.1415926 * (t - 0.5)));
}
double cur::inQuad(double t) {
return t * t;
}
double cur::outQuad(double t) {
return t * (2 - t);
}
double cur::inOutQuad(double t) {
return t < 0.5 ? 2 * t * t : t * (4 - 2 * t) - 1;
}
double cur::inCubic(double t) {
return t * t * t;
}
double cur::outCubic(double t) {
return 1 + (--t) * t * t;
}
double cur::inOutCubic(double t) {
return t < 0.5 ? 4 * t * t * t : 1 + (--t) * (2 * (--t)) * (2 * t);
}
double cur::inQuart(double t) {
t *= t;
return t * t;
}
double cur::outQuart(double t) {
t = (--t) * t;
return 1 - t * t;
}
double cur::inOutQuart(double t) {
if(t < 0.5) {
t *= t;
return 8 * t * t;
} else {
t = (--t) * t;
return 1 - 8 * t * t;
} }
}
// Modeled after the parabola y = x^2 double cur::inQuint(double t) {
EASING_TYPE QuadraticEaseIn(EASING_TYPE p) auto t2 = t * t;
{ return t * t2 * t2;
return p * p; }
double cur::outQuint(double t) {
auto t2 = (--t) * t;
return 1 + t * t2 * t2;
}
double cur::inOutQuint(double t) {
auto t2 = double { 0.0 };
if(t < 0.5) {
t2 = t * t;
return 16 * t * t2 * t2;
} else {
t2 = (--t) * t;
return 1 + 16 * t * t2 * t2;
} }
}
// Modeled after the parabola y = -x^2 + 2x double cur::inExpo(double t) {
EASING_TYPE QuadraticEaseOut(EASING_TYPE p) return (pow(2, 8 * t) - 1) / 255;
{ }
return -(p * (p - 2));
double cur::outExpo(double t) {
return 1 - pow(2, -8 * t);
}
double cur::inOutExpo(double t) {
if(t < 0.5) {
return (pow(2, 16 * t) - 1) / 510;
} else {
return 1 - 0.5 * pow(2, -16 * (t - 0.5));
} }
}
// Modeled after the piecewise quadratic double cur::inCirc(double t) {
// y = (1/2)((2x)^2) ; [0, 0.5) return 1 - sqrt(1 - t);
// y = -(1/2)((2x-1)*(2x-3) - 1) ; [0.5, 1] }
EASING_TYPE QuadraticEaseInOut(EASING_TYPE p)
{ double cur::outCirc(double t) {
if(p < 0.5) return sqrt(t);
{ }
return 2 * p * p;
} double cur::inOutCirc(double t) {
else if(t < 0.5) {
{ return (1 - sqrt(1 - 2 * t)) * 0.5;
return (-2 * p * p) + (4 * p) - 1; } else {
} return (1 + sqrt(2 * t - 1)) * 0.5;
} }
}
// Modeled after the cubic y = x^3 double cur::inBack(double t) {
EASING_TYPE CubicEaseIn(EASING_TYPE p) return t * t * (2.70158 * t - 1.70158);
{ }
return p * p * p;
double cur::outBack(double t) {
return 1 + (--t) * t * (2.70158 * t + 1.70158);
}
double cur::inOutBack(double t) {
if(t < 0.5) {
return t * t * (7 * t - 2.5) * 2;
} else {
return 1 + (--t) * t * 2 * (7 * t + 2.5);
} }
}
// Modeled after the cubic y = (x - 1)^3 + 1 double cur::inElastic(double t) {
EASING_TYPE CubicEaseOut(EASING_TYPE p) auto t2 = t * t;
{ return t2 * t2 * sin(t * PI * 4.5);
EASING_TYPE f = (p - 1); }
return f * f * f + 1;
double cur::outElastic(double t) {
auto t2 = (t - 1) * (t - 1);
return 1 - t2 * t2 * cos(t * PI * 4.5);
}
double cur::inOutElastic(double t) {
auto t2 = double { 0.0 };
if(t < 0.45) {
t2 = t * t;
return 8 * t2 * t2 * sin(t * PI * 9);
} else if(t < 0.55) {
return 0.5 + 0.75 * sin(t * PI * 4);
} else {
t2 = (t - 1) * (t - 1);
return 1 - 8 * t2 * t2 * sin(t * PI * 9);
} }
}
// Modeled after the piecewise cubic double cur::inBounce(double t) {
// y = (1/2)((2x)^3) ; [0, 0.5) return pow(2, 6 * (t - 1)) * abs(sin(t * PI * 3.5));
// y = (1/2)((2x-2)^3 + 2) ; [0.5, 1] }
EASING_TYPE CubicEaseInOut(EASING_TYPE p)
{
if(p < 0.5)
{
return 4 * p * p * p;
}
else
{
EASING_TYPE f = ((2 * p) - 2);
return 0.5 * f * f * f + 1;
}
}
// Modeled after the quartic x^4 double cur::outBounce(double t) {
EASING_TYPE QuarticEaseIn(EASING_TYPE p) return 1 - pow(2, -6 * t) * abs(cos(t * PI * 3.5));
{ }
return p * p * p * p;
}
// Modeled after the quartic y = 1 - (x - 1)^4 double cur::inOutBounce(double t) {
EASING_TYPE QuarticEaseOut(EASING_TYPE p) if(t < 0.5) {
{ return 8 * pow(2, 8 * (t - 1)) * abs(sin(t * PI * 7));
EASING_TYPE f = (p - 1); } else {
return f * f * f * (1 - p) + 1; return 1 - 8 * pow(2, -8 * t) * abs(sin(t * PI * 7));
}
// Modeled after the piecewise quartic
// y = (1/2)((2x)^4) ; [0, 0.5)
// y = -(1/2)((2x-2)^4 - 2) ; [0.5, 1]
EASING_TYPE QuarticEaseInOut(EASING_TYPE p)
{
if(p < 0.5)
{
return 8 * p * p * p * p;
}
else
{
EASING_TYPE f = (p - 1);
return -8 * f * f * f * f + 1;
}
}
// Modeled after the quintic y = x^5
EASING_TYPE QuinticEaseIn(EASING_TYPE p)
{
return p * p * p * p * p;
}
// Modeled after the quintic y = (x - 1)^5 + 1
EASING_TYPE QuinticEaseOut(EASING_TYPE p)
{
EASING_TYPE f = (p - 1);
return f * f * f * f * f + 1;
}
// Modeled after the piecewise quintic
// y = (1/2)((2x)^5) ; [0, 0.5)
// y = (1/2)((2x-2)^5 + 2) ; [0.5, 1]
EASING_TYPE QuinticEaseInOut(EASING_TYPE p)
{
if(p < 0.5)
{
return 16 * p * p * p * p * p;
}
else
{
EASING_TYPE f = ((2 * p) - 2);
return 0.5 * f * f * f * f * f + 1;
}
}
// Modeled after quarter-cycle of sine wave
EASING_TYPE SineEaseIn(EASING_TYPE p)
{
return sin((p - 1) * M_PI_2) + 1;
}
// Modeled after quarter-cycle of sine wave (different phase)
EASING_TYPE SineEaseOut(EASING_TYPE p)
{
return sin(p * M_PI_2);
}
// Modeled after half sine wave
EASING_TYPE SineEaseInOut(EASING_TYPE p)
{
return 0.5 * (1 - cos(p * M_PI));
}
// Modeled after shifted quadrant IV of unit circle
EASING_TYPE CircularEaseIn(EASING_TYPE p)
{
return 1 - sqrt(1 - (p * p));
}
// Modeled after shifted quadrant II of unit circle
EASING_TYPE CircularEaseOut(EASING_TYPE p)
{
return sqrt((2 - p) * p);
}
// Modeled after the piecewise circular function
// y = (1/2)(1 - sqrt(1 - 4x^2)) ; [0, 0.5)
// y = (1/2)(sqrt(-(2x - 3)*(2x - 1)) + 1) ; [0.5, 1]
EASING_TYPE CircularEaseInOut(EASING_TYPE p)
{
if(p < 0.5)
{
return 0.5 * (1 - sqrt(1 - 4 * (p * p)));
}
else
{
return 0.5 * (sqrt(-((2 * p) - 3) * ((2 * p) - 1)) + 1);
}
}
// Modeled after the exponential function y = 2^(10(x - 1))
EASING_TYPE ExponentialEaseIn(EASING_TYPE p)
{
return (p == 0.0) ? p : pow(2, 10 * (p - 1));
}
// Modeled after the exponential function y = -2^(-10x) + 1
EASING_TYPE ExponentialEaseOut(EASING_TYPE p)
{
return (p == 1.0) ? p : 1 - pow(2, -10 * p);
}
// Modeled after the piecewise exponential
// y = (1/2)2^(10(2x - 1)) ; [0,0.5)
// y = -(1/2)*2^(-10(2x - 1))) + 1 ; [0.5,1]
EASING_TYPE ExponentialEaseInOut(EASING_TYPE p)
{
if(p == 0.0 || p == 1.0) return p;
if(p < 0.5)
{
return 0.5 * pow(2, (20 * p) - 10);
}
else
{
return -0.5 * pow(2, (-20 * p) + 10) + 1;
}
}
// Modeled after the damped sine wave y = sin(13pi/2*x)*pow(2, 10 * (x - 1))
EASING_TYPE ElasticEaseIn(EASING_TYPE p)
{
return sin(13 * M_PI_2 * p) * pow(2, 10 * (p - 1));
}
// Modeled after the damped sine wave y = sin(-13pi/2*(x + 1))*pow(2, -10x) + 1
EASING_TYPE ElasticEaseOut(EASING_TYPE p)
{
return sin(-13 * M_PI_2 * (p + 1)) * pow(2, -10 * p) + 1;
}
// Modeled after the piecewise exponentially-damped sine wave:
// y = (1/2)*sin(13pi/2*(2*x))*pow(2, 10 * ((2*x) - 1)) ; [0,0.5)
// y = (1/2)*(sin(-13pi/2*((2x-1)+1))*pow(2,-10(2*x-1)) + 2) ; [0.5, 1]
EASING_TYPE ElasticEaseInOut(EASING_TYPE p)
{
if(p < 0.5)
{
return 0.5 * sin(13 * M_PI_2 * (2 * p)) * pow(2, 10 * ((2 * p) - 1));
}
else
{
return 0.5 * (sin(-13 * M_PI_2 * ((2 * p - 1) + 1)) * pow(2, -10 * (2 * p - 1)) + 2);
}
}
// Modeled after the overshooting cubic y = x^3-x*sin(x*pi)
EASING_TYPE BackEaseIn(EASING_TYPE p)
{
return p * p * p - p * sin(p * M_PI);
}
// Modeled after overshooting cubic y = 1-((1-x)^3-(1-x)*sin((1-x)*pi))
EASING_TYPE BackEaseOut(EASING_TYPE p)
{
EASING_TYPE f = (1 - p);
return 1 - (f * f * f - f * sin(f * M_PI));
}
// Modeled after the piecewise overshooting cubic function:
// y = (1/2)*((2x)^3-(2x)*sin(2*x*pi)) ; [0, 0.5)
// y = (1/2)*(1-((1-x)^3-(1-x)*sin((1-x)*pi))+1) ; [0.5, 1]
EASING_TYPE BackEaseInOut(EASING_TYPE p)
{
if(p < 0.5)
{
EASING_TYPE f = 2 * p;
return 0.5 * (f * f * f - f * sin(f * M_PI));
}
else
{
EASING_TYPE f = (1 - (2*p - 1));
return 0.5 * (1 - (f * f * f - f * sin(f * M_PI))) + 0.5;
}
}
EASING_TYPE BounceEaseIn(EASING_TYPE p)
{
return 1 - BounceEaseOut(1 - p);
}
EASING_TYPE BounceEaseOut(EASING_TYPE p)
{
if(p < 4/11.0)
{
return (121 * p * p)/16.0;
}
else if(p < 8/11.0)
{
return (363/40.0 * p * p) - (99/10.0 * p) + 17/5.0;
}
else if(p < 9/10.0)
{
return (4356/361.0 * p * p) - (35442/1805.0 * p) + 16061/1805.0;
}
else
{
return (54/5.0 * p * p) - (513/25.0 * p) + 268/25.0;
}
}
EASING_TYPE BounceEaseInOut(EASING_TYPE p)
{
if(p < 0.5)
{
return 0.5 * BounceEaseIn(p*2);
}
else
{
return 0.5 * BounceEaseOut(p * 2 - 1) + 0.5;
}
}
EASING_TYPE BounceTwice(EASING_TYPE p)
{
EASING_TYPE cutoff1 = 4.0f/6.0f;
if(p < cutoff1)
{
return sinf(p/cutoff1*M_PI);
}
else
{
return (1.0 - cutoff1) * sinf((p-cutoff1)/(1.0f-cutoff1)*M_PI);
}
} }
} }

View File

@ -1,63 +1,36 @@
#pragma once #pragma once
#ifndef EASING_TYPE
#define EASING_TYPE float
#endif
namespace easing namespace easing
{ {
// Linear interpolation (no easing) double inSine(double time);
EASING_TYPE LinearInterpolation(EASING_TYPE p); double outSine(double time);
double inOutSine(double time);
// Quadratic easing; p^2 double inQuad(double time);
EASING_TYPE QuadraticEaseIn(EASING_TYPE p); double outQuad(double time);
EASING_TYPE QuadraticEaseOut(EASING_TYPE p); double inOutQuad(double time);
EASING_TYPE QuadraticEaseInOut(EASING_TYPE p); double inCubic(double time);
double outCubic(double time);
// Cubic easing; p^3 double inOutCubic(double time);
EASING_TYPE CubicEaseIn(EASING_TYPE p); double inQuart(double time);
EASING_TYPE CubicEaseOut(EASING_TYPE p); double outQuart(double time);
EASING_TYPE CubicEaseInOut(EASING_TYPE p); double inOutQuart(double time);
double inQuint(double time);
// Quartic easing; p^4 double outQuint(double time);
EASING_TYPE QuarticEaseIn(EASING_TYPE p); double inOutQuint(double time);
EASING_TYPE QuarticEaseOut(EASING_TYPE p); double inExpo(double time);
EASING_TYPE QuarticEaseInOut(EASING_TYPE p); double outExpo(double time);
double inOutExpo(double time);
// Quintic easing; p^5 double inOutExpo(double time);
EASING_TYPE QuinticEaseIn(EASING_TYPE p); double inCirc(double time);
EASING_TYPE QuinticEaseOut(EASING_TYPE p); double outCirc(double time);
EASING_TYPE QuinticEaseInOut(EASING_TYPE p); double inOutCirc(double time);
double inBack(double time);
// Sine wave easing; sin(p * PI/2) double outBack(double time);
EASING_TYPE SineEaseIn(EASING_TYPE p); double inOutBack(double time);
EASING_TYPE SineEaseOut(EASING_TYPE p); double inElastic(double time);
EASING_TYPE SineEaseInOut(EASING_TYPE p); double outElastic(double time);
double inOutElastic(double time);
// Circular easing; sqrt(1 - p^2) double inBounce(double time);
EASING_TYPE CircularEaseIn(EASING_TYPE p); double outBounce(double time);
EASING_TYPE CircularEaseOut(EASING_TYPE p); double inOutBounce(double time);
EASING_TYPE CircularEaseInOut(EASING_TYPE p);
// Exponential easing, base 2
EASING_TYPE ExponentialEaseIn(EASING_TYPE p);
EASING_TYPE ExponentialEaseOut(EASING_TYPE p);
EASING_TYPE ExponentialEaseInOut(EASING_TYPE p);
// Exponentially-damped sine wave easing
EASING_TYPE ElasticEaseIn(EASING_TYPE p);
EASING_TYPE ElasticEaseOut(EASING_TYPE p);
EASING_TYPE ElasticEaseInOut(EASING_TYPE p);
// Overshooting cubic easing;
EASING_TYPE BackEaseIn(EASING_TYPE p);
EASING_TYPE BackEaseOut(EASING_TYPE p);
EASING_TYPE BackEaseInOut(EASING_TYPE p);
// Exponentially-decaying bounce easing
EASING_TYPE BounceEaseIn(EASING_TYPE p);
EASING_TYPE BounceEaseOut(EASING_TYPE p);
EASING_TYPE BounceEaseInOut(EASING_TYPE p);
EASING_TYPE BounceTwice(EASING_TYPE p);
} }