Added linear interpolation with time.

This commit is contained in:
Ulysse Cura 2026-09-01 17:29:56 +02:00
parent 0070779007
commit 6ce19277e5
3 changed files with 27 additions and 4 deletions

View File

@ -34,7 +34,7 @@ CORE_AR = ar
CORE_ARFLAGS =
# Used in final linking.
CORE_DEPS_FLAGS = $(shell pkg-config --libs sdl3)
CORE_DEPS_FLAGS = $(shell pkg-config --libs sdl3) -lm
# Deduce objects
CORE_OBJECTS = $(CORE_SOURCES:%.c=$(BUILD_DIR)/$(CORE_DIR)/%.o)

View File

@ -130,6 +130,24 @@ void frect_to_rect(const frect_t *frect, rect_t *rect);
*/
#define intersect_frect(A, B, result) SDL_GetRectIntersectionFloat(A, B, result)
float lerp(float a, float b, float t);
/**
* @brief Lerp a to b with smoothing factor s.
*
* @param a Current value
* @param b Target value
* @param s Smoothing factor
*/
float lerp(float a, float b, float s);
/**
* @brief Lerp a to b with smoothing factor s and time basis t.
* Smoothing factor is for 60 fps call time.
*
* @param a Current value
* @param b Target value
* @param s Smoothing factor
* @param t Delta time
*/
float lerp_time(float a, float b, float s, float t);
#endif // VECTOR2D_H

View File

@ -16,7 +16,12 @@ void frect_to_rect(const frect_t *frect, rect_t *rect)
rect->h = (int)frect->h;
}
float lerp(float a, float b, float t)
inline float lerp(float a, float b, float s)
{
return a * (1 - t) + b * t;
return a * (1 - s) + b * s;
}
inline float lerp_time(float a, float b, float s, float t)
{
return lerp(a, b, 1 - powf(1 - s, t * 60.0f));
}