Implement basic keyframe-per-frame animation

This commit is contained in:
Camden Dixie O'Brien committed 2025-10-02 15:32:46 +01:00
1 parent 2a603dc364
commit 4c94812b48
3 files changed
+40 -53

No files matched your search

+13 -41
View File
@@ -10,14 +10,6 @@
#define W 800
#define H 600
typedef enum {
AXIS_X,
AXIS_Y,
AXIS_Z,
} axis_t;
static axis_t rot_axis = AXIS_Y;
static void
key_callback(GLFWwindow *window, int key, int scancode, int action, int mods)
{
@@ -32,16 +24,6 @@ key_callback(GLFWwindow *window, int key, int scancode, int action, int mods)
case GLFW_KEY_Q:
glfwSetWindowShouldClose(window, GL_TRUE);
break;
case GLFW_KEY_X:
rot_axis = AXIS_X;
break;
case GLFW_KEY_Y:
rot_axis = AXIS_Y;
break;
case GLFW_KEY_Z:
rot_axis = AXIS_Z;
break;
}
}
@@ -74,40 +56,30 @@ int main(int argc, char *argv[])
// Initialise animation
animation_state_t anim = animation_init(&model);
animation_update(anim, &model);
const vec3_t cam = { 0, 4, -4 };
const vec3_t tgt = { 0, 0.5, 0 };
mvp_t mvp = {
.model = (mat4_t) {
{ 0, 0, -1, 0 },
{ -1, 0, 0, 0 },
{ 0, 1, 0, 0 },
{ 0, 0, 0, 1 },
},
.model = mat4_mul(
MAT4_TRANSLATE(1, 0, 0),
(mat4_t) {
{ 0, 0, -1, 0 },
{ -1, 0, 0, 0 },
{ 0, 1, 0, 0 },
{ 0, 0, 0, 1 },
}),
.view = mat4_lookat(cam, tgt, (vec3_t) { 0, 1, 0 }),
.proj = mat4_perspective((float)W / H, PI / 12, 0.1, 10.0),
.proj = mat4_perspective((float)W / H, PI / 8, 0.1, 10.0),
};
const mat4_t rotx = MAT4_ROTATE_X(PI / 128);
const mat4_t roty = MAT4_ROTATE_Y(PI / 128);
const mat4_t rotz = MAT4_ROTATE_Z(PI / 128);
const mat4_t rot = MAT4_ROTATE_Y(PI / 128);
animation_start(&anim, &model);
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
switch (rot_axis) {
case AXIS_X:
mvp.model = mat4_mul(rotx, mvp.model);
break;
case AXIS_Y:
mvp.model = mat4_mul(roty, mvp.model);
break;
case AXIS_Z:
mvp.model = mat4_mul(rotz, mvp.model);
break;
}
mvp.model = mat4_mul(rot, mvp.model);
animation_update(&anim, &model);
gpu_render(&gpu, &mvp, anim.bone_matrices);
}