From 62b6f55a14f71c62c55e3b6747d37da595d9d44f Mon Sep 17 00:00:00 2001 From: Noah Metz Date: Mon, 8 Jan 2024 17:50:24 -0700 Subject: [PATCH] More movement fixes --- src/main.c | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/src/main.c b/src/main.c index 0a3abdd..e2032be 100644 --- a/src/main.c +++ b/src/main.c @@ -127,14 +127,12 @@ const struct Vertex vertices[] = { {.pos = { 0.5f, -0.5f, 0.5f}, .color = {0.0f, 1.0f, 0.0f}}, {.pos = { 0.5f, 0.5f, 0.5f}, .color = {0.0f, 0.0f, 1.0f}}, {.pos = {-0.5f, 0.5f, 0.5f}, .color = {1.0f, 1.0f, 1.0f}}, + {.pos = { 0.5f, 0.5f, 1.0f}, .color = {0.0f, 0.0f, 1.0f}}, + {.pos = {-0.5f, 0.5f, 1.0f}, .color = {1.0f, 1.0f, 1.0f}}, }; -//const uint16_t indices[] = { -// 0, 1, 2, 2, 3, 0, -//}; -// const uint16_t indices[] = { - 2, 1, 0, 0, 3, 2, + 2, 1, 0, 0, 3, 2, 5, 4, 3, }; const char * validation_layers[] = { @@ -1647,7 +1645,7 @@ VulkanContext* init_vulkan(GLFWwindow* window, uint32_t max_frames_in_flight) { context->simple_mesh_material = simple_mesh_material; } - Mesh triangle_mesh = load_mesh(context->physical_device, context->device, (struct Vertex*)vertices, 4, (uint16_t*)indices, 6, context->transfer_command_pool, context->queues.transfer); + Mesh triangle_mesh = load_mesh(context->physical_device, context->device, (struct Vertex*)vertices, 6, (uint16_t*)indices, 9, context->transfer_command_pool, context->queues.transfer); if(triangle_mesh.vertex_buffer.buffer == VK_NULL_HANDLE) { fprintf(stderr, "failed to load triangle mesh\n"); } else { @@ -1664,6 +1662,8 @@ struct { bool backward: 1; bool left: 1; bool right: 1; + bool up: 1; + bool down: 1; bool turn_left: 1; bool turn_right: 1; } key_flags = { @@ -1711,6 +1711,22 @@ void key_callback(GLFWwindow* window, int key, int scancode, int action, int mod } break; + case GLFW_KEY_SPACE: + if(action == GLFW_PRESS) { + key_flags.up = true; + } else if(action == GLFW_RELEASE) { + key_flags.up = false; + } + break; + + case GLFW_KEY_LEFT_SHIFT: + if(action == GLFW_PRESS) { + key_flags.down = true; + } else if(action == GLFW_RELEASE) { + key_flags.down = false; + } + break; + case GLFW_KEY_RIGHT: if(action == GLFW_PRESS) { key_flags.turn_right = true; @@ -1741,11 +1757,19 @@ VkResult update_ubo(void** buffers, uint32_t frame_index) { } if(key_flags.left) { - movement_sum[0] += 0.01; + movement_sum[0] -= 0.01; } if(key_flags.right) { - movement_sum[0] -= 0.01; + movement_sum[0] += 0.01; + } + + if(key_flags.up) { + movement_sum[1] += 0.01; + } + + if(key_flags.down) { + movement_sum[1] -= 0.01; } if(key_flags.turn_right) { @@ -1757,7 +1781,7 @@ VkResult update_ubo(void** buffers, uint32_t frame_index) { } vec3 forward = {0.0f, 0.0f, 1.0f}; - vec3 up = {0.0f, 1.0f, 0.0f}; + vec3 up = {0.0f, -1.0f, 0.0f}; vec3 dir; mat4 rot;