From b67db796d4e5eb30afd319d021573b53eba61730 Mon Sep 17 00:00:00 2001 From: Chukobyte Date: Sun, 28 Jan 2024 18:09:30 -0500 Subject: [PATCH] Adding transform2d lerp. --- seika/math/se_math.c | 18 +++++++++++++----- seika/math/se_math.h | 5 +++-- vcpkg.json | 2 +- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/seika/math/se_math.c b/seika/math/se_math.c index cf0ee19..40e46b6 100644 --- a/seika/math/se_math.c +++ b/seika/math/se_math.c @@ -5,10 +5,10 @@ bool ska_math_vec2_equals(const SKAVector2* v1, const SKAVector2* v2) { return v1->x == v2->x && v1->y == v2->y; } -SKAVector2 ska_math_vec2_lerp(const SKAVector2* v1, const SKAVector2* v2, float t) { +SKAVector2 ska_math_vec2_lerp(const SKAVector2* v1, const SKAVector2* v2, float alpha) { return (SKAVector2) { - .x = ska_math_lerpf(v1->x, v2->x, t), - .y = ska_math_lerpf(v1->y, v2->y, t) + .x = ska_math_lerpf(v1->x, v2->x, alpha), + .y = ska_math_lerpf(v1->y, v2->y, alpha) }; } @@ -55,6 +55,14 @@ void ska_transform2d_transform_to_mat4(const SKATransform2D* transform, mat4 mat glm_scale(matrix, (vec3){transform->scale.x, transform->scale.y, 1.0f}); } +SKATransform2D ska_transform2d_lerp(const SKATransform2D* tA, const SKATransform2D* tB, float alpha) { + return (SKATransform2D) { + .position = ska_math_vec2_lerp(&tA->position, &tB->position, alpha), + .scale = ska_math_vec2_lerp(&tA->scale, &tB->scale, alpha), + .rotation = ska_math_lerpf(tA->rotation, tB->rotation, alpha) + }; +} + // --- Transform2D Model --- // SKATransform2D ska_transform2d_model_convert_to_transform(SKATransformModel2D* transformModel2D) { SKATransform2D transform2D; @@ -104,8 +112,8 @@ SKAVector2 ska_math_minmax_vec2_get_random_in_range(const SKAMinMaxVec2* minmax) } // --- Misc --- // -float ska_math_lerpf(float a, float b, float t) { - return a + (b - a) * t; +float ska_math_lerpf(float a, float b, float alpha) { + return a + (b - a) * alpha; } float ska_math_map_to_range(float input, float inputMin, float inputMax, float outputMin, float outputMax) { diff --git a/seika/math/se_math.h b/seika/math/se_math.h index e7e9ae2..5dc44a8 100644 --- a/seika/math/se_math.h +++ b/seika/math/se_math.h @@ -33,7 +33,7 @@ typedef struct SKAVector2 { #define SKA_VECTOR2_DOWN SKA_STRUCT_LITERAL(SKAVector2){ 0.0f, 1.0f } bool ska_math_vec2_equals(const SKAVector2* v1, const SKAVector2* v2); -SKAVector2 ska_math_vec2_lerp(const SKAVector2* v1, const SKAVector2* v2, float t); +SKAVector2 ska_math_vec2_lerp(const SKAVector2* v1, const SKAVector2* v2, float alpha); float ska_math_vec2_angle(const SKAVector2* v); // --- SKAVector2i --- // @@ -77,6 +77,7 @@ typedef struct SKATransform2D { void ska_transform2d_mat4_to_transform(mat4 matrix, SKATransform2D* transform); void ska_transform2d_transform_to_mat4(const SKATransform2D* transform, mat4 matrix); +SKATransform2D ska_transform2d_lerp(const SKATransform2D* tA, const SKATransform2D* tB, float alpha); #define SKA_TRANSFORM_IDENTITY SKA_STRUCT_LITERAL(SKATransform2D){ \ .position = SKA_VECTOR2_ZERO, \ @@ -147,7 +148,7 @@ typedef struct SKAMinMaxVec2 { SKAVector2 ska_math_minmax_vec2_get_random_in_range(const SKAMinMaxVec2* minmax); // --- Misc --- // -float ska_math_lerpf(float a, float b, float t); +float ska_math_lerpf(float a, float b, float alpha); float ska_math_map_to_range(float input, float inputMin, float inputMax, float outputMin, float outputMax); float ska_math_map_to_unit(float input, float inputMin, float inputMax); double ska_math_map_to_range_double(double input, double inputMin, double inputMax, double outputMin, double outputMax); diff --git a/vcpkg.json b/vcpkg.json index 2a9d83f..b7ac841 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -1,6 +1,6 @@ { "name": "seika", - "version": "0.0.24", + "version": "0.0.25", "dependencies": [ { "name": "sdl2",