Restructure things a little to enable multiple models

This commit is contained in:
Camden Dixie O'Brien committed 2025-10-03 22:33:11 +01:00
1 parent 4c3fe8d8f7
commit f3aa7435ec
3 files changed
+235 -184

No files matched your search

+34 -11
View File
@@ -12,6 +12,8 @@
#define DT (1'000'000 / 60) // Assume 60 Hz for now
#define LIL_GUY_COUNT 2
static void
key_callback(GLFWwindow *window, int key, int scancode, int action, int mods)
{
@@ -48,22 +50,21 @@ int main(int argc, char *argv[])
// Register input callbacks
glfwSetKeyCallback(window, key_callback);
// Initialise GPU
const gpu_config_t gpu_config = {
.application_name = "Foo",
.window = window,
};
// Initialise GPU and load model
gpu_ctx_t gpu;
gpu_init(&gpu, &gpu_config, model);
gpu_model_t gpu_model1, gpu_model2;
gpu_init(&gpu, window, "Foo");
gpu_model_load(&gpu, &model, &gpu_model1);
gpu_model_load(&gpu, &model, &gpu_model2);
// Initialise animation
animation_state_t anim = animation_init(&model);
const vec3_t cam = { 0, 4, -4 };
const vec3_t tgt = { 0, 0.5, 0 };
mvp_t mvp = {
mvp_t mvp1 = {
.model = mat4_mul(
MAT4_TRANSLATE(1, 0, 0),
MAT4_TRANSLATE(1, 0, 0),
(mat4_t) {
{ 0, 0, -1, 0 },
{ -1, 0, 0, 0 },
@@ -73,20 +74,42 @@ int main(int argc, char *argv[])
.view = mat4_lookat(cam, tgt, (vec3_t) { 0, 1, 0 }),
.proj = mat4_perspective((float)W / H, PI / 8, 0.1, 10.0),
};
mvp_t mvp2 = {
.model = mat4_mul(
MAT4_TRANSLATE(2, 0, 0),
mat4_mul(
MAT4_ROTATE_Y(PI),
(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 / 8, 0.1, 10.0),
};
const mat4_t rot = MAT4_ROTATE_Y(PI / 170);
const mat4_t rot1 = MAT4_ROTATE_Y(PI / 170);
const mat4_t rot2 = MAT4_ROTATE_Y(-PI / 340);
animation_start(&anim, &model, 0);
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
mvp.model = mat4_mul(rot, mvp.model);
mvp1.model = mat4_mul(rot1, mvp1.model);
mvp2.model = mat4_mul(rot2, mvp2.model);
animation_update(&anim, &model, DT);
gpu_render(&gpu, &mvp, anim.bone_matrices);
gpu_render_begin(&gpu);
gpu_render_model(&gpu, &gpu_model1, &mvp1, anim.bone_matrices);
gpu_render_model(&gpu, &gpu_model2, &mvp2, anim.bone_matrices);
gpu_render_submit(&gpu);
}
// Clean up
animation_cleanup(&anim);
gpu_model_cleanup(&gpu, &gpu_model1);
gpu_model_cleanup(&gpu, &gpu_model2);
gpu_cleanup(&gpu);
model_cleanup(&model);
glfwDestroyWindow(window);