Skip to content

Commit

Permalink
Adding transform2d lerp.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chukobyte committed Jan 28, 2024
1 parent 6d6a33d commit b67db79
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
18 changes: 13 additions & 5 deletions seika/math/se_math.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
};
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions seika/math/se_math.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 --- //
Expand Down Expand Up @@ -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, \
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "seika",
"version": "0.0.24",
"version": "0.0.25",
"dependencies": [
{
"name": "sdl2",
Expand Down

0 comments on commit b67db79

Please sign in to comment.