From 199aa18d5822c12be85e7c7bf6965a893d940fd0 Mon Sep 17 00:00:00 2001 From: Noah Metz Date: Mon, 8 Jan 2024 17:45:10 -0700 Subject: [PATCH] Fixed movement directions and perspective --- src/main.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/main.c b/src/main.c index 1624bf5..0a3abdd 100644 --- a/src/main.c +++ b/src/main.c @@ -9,6 +9,7 @@ #define GLM_FORCE_DEPTH_ZERO_TO_ONE #include #include +#include #include #include #include @@ -1729,32 +1730,32 @@ void key_callback(GLFWwindow* window, int key, int scancode, int action, int mod } VkResult update_ubo(void** buffers, uint32_t frame_index) { + vec3 movement_sum = {0.0f, 0.0f, 0.0f}; + if(key_flags.forward) { - world_position[2] += 0.01; + movement_sum[2] += 0.01; } if(key_flags.backward) { - world_position[2] -= 0.01; + movement_sum[2] -= 0.01; } if(key_flags.left) { - world_position[0] -= 0.01; + movement_sum[0] += 0.01; } if(key_flags.right) { - world_position[0] += 0.01; + movement_sum[0] -= 0.01; } if(key_flags.turn_right) { - rotation += 0.01; + rotation -= 0.01; } if(key_flags.turn_left) { - rotation -= 0.01; + rotation += 0.01; } - struct SceneUBO ubo = {}; - glm_perspective(30.0f, 800.0/600.0, 0.1, 1, ubo.proj); vec3 forward = {0.0f, 0.0f, 1.0f}; vec3 up = {0.0f, 1.0f, 0.0f}; @@ -1763,6 +1764,12 @@ VkResult update_ubo(void** buffers, uint32_t frame_index) { glm_rotate_make(rot, rotation, up); glm_mat4_mulv3(rot, forward, 1.0f, dir); + vec3 movement_rot; + glm_mat4_mulv3(rot, movement_sum, 1.0f, movement_rot); + glm_vec3_add(movement_rot, world_position, world_position); + + struct SceneUBO ubo = {}; + glm_perspective(90.0f, 800.0/600.0, 0.1, 100, ubo.proj); glm_look(world_position, dir, up, ubo.view); memcpy(buffers[frame_index], (void*)&ubo, sizeof(ubo));