Implement linear interpolation between animation keyframes

This commit is contained in:
Camden Dixie O'Brien committed 2025-10-02 17:28:03 +01:00
1 parent 381890892b
commit f4096b5a07
6 files changed
+103 -29

No files matched your search

+26 -1
View File
@@ -2,11 +2,21 @@
#include <math.h>
vec3_t vec3_add(vec3_t v, vec3_t u)
{
return (vec3_t) { v.x + u.x, v.y + u.y, v.z + u.z };
}
vec3_t vec3_sub(vec3_t v, vec3_t u)
{
return (vec3_t) { v.x - u.x, v.y - u.y, v.z - u.z };
}
vec3_t vec3_scale(float s, vec3_t v)
{
return (vec3_t) { s * v.x, s * v.y, s * v.z };
}
float vec3_len(vec3_t v)
{
return sqrtf(v.x * v.x + v.y * v.y + v.z * v.z);
@@ -15,7 +25,7 @@ float vec3_len(vec3_t v)
vec3_t vec3_norm(vec3_t v)
{
const float l = vec3_len(v);
return (vec3_t) { v.x / l, v.y / l, v.z / l };
return vec3_scale(1 / l, v);
}
float vec3_dot(vec3_t v, vec3_t u)
@@ -32,6 +42,21 @@ vec3_t vec3_cross(vec3_t v, vec3_t u)
};
}
vec4_t vec4_add(vec4_t v, vec4_t u)
{
return (vec4_t) { v.x + u.x, v.y + u.y, v.z + u.z, v.w + u.w };
}
vec4_t vec4_scale(float s, vec4_t v)
{
return (vec4_t) { s * v.x, s * v.y, s * v.z, s * v.w };
}
float vec4_dot(vec4_t v, vec4_t u)
{
return v.x * u.x + v.y * u.y + v.z * u.z + v.w * u.w;
}
mat4_t mat4_mul(mat4_t m, mat4_t n)
{
#define ELEM(i, j) m.x.i *n.j.x + m.y.i *n.j.y + m.z.i *n.j.z + m.w.i *n.j.w