|
|
@ -1745,39 +1745,39 @@ void key_callback(GLFWwindow* window, int key, int scancode, int action, int mod
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VkResult update_ubo(void** buffers, uint32_t frame_index) {
|
|
|
|
VkResult update_scene_ubo(void** buffers, uint32_t frame_index, vec3 world_position, float* rotation, float aspect_ratio, float time_delta) {
|
|
|
|
vec3 movement_sum = {0.0f, 0.0f, 0.0f};
|
|
|
|
vec3 movement_sum = {0.0f, 0.0f, 0.0f};
|
|
|
|
|
|
|
|
|
|
|
|
if(key_flags.forward) {
|
|
|
|
if(key_flags.forward) {
|
|
|
|
movement_sum[2] += 0.01;
|
|
|
|
movement_sum[2] += 1 * time_delta;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(key_flags.backward) {
|
|
|
|
if(key_flags.backward) {
|
|
|
|
movement_sum[2] -= 0.01;
|
|
|
|
movement_sum[2] -= 1 * time_delta;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(key_flags.left) {
|
|
|
|
if(key_flags.left) {
|
|
|
|
movement_sum[0] -= 0.01;
|
|
|
|
movement_sum[0] -= 1 * time_delta;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(key_flags.right) {
|
|
|
|
if(key_flags.right) {
|
|
|
|
movement_sum[0] += 0.01;
|
|
|
|
movement_sum[0] += 1 * time_delta;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(key_flags.up) {
|
|
|
|
if(key_flags.up) {
|
|
|
|
movement_sum[1] += 0.01;
|
|
|
|
movement_sum[1] += 1 * time_delta;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(key_flags.down) {
|
|
|
|
if(key_flags.down) {
|
|
|
|
movement_sum[1] -= 0.01;
|
|
|
|
movement_sum[1] -= 1 * time_delta;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(key_flags.turn_right) {
|
|
|
|
if(key_flags.turn_right) {
|
|
|
|
rotation -= 0.01;
|
|
|
|
*rotation -= 1 * time_delta;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(key_flags.turn_left) {
|
|
|
|
if(key_flags.turn_left) {
|
|
|
|
rotation += 0.01;
|
|
|
|
*rotation += 1 * time_delta;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
vec3 forward = {0.0f, 0.0f, 1.0f};
|
|
|
|
vec3 forward = {0.0f, 0.0f, 1.0f};
|
|
|
@ -1785,7 +1785,7 @@ VkResult update_ubo(void** buffers, uint32_t frame_index) {
|
|
|
|
|
|
|
|
|
|
|
|
vec3 dir;
|
|
|
|
vec3 dir;
|
|
|
|
mat4 rot;
|
|
|
|
mat4 rot;
|
|
|
|
glm_rotate_make(rot, rotation, up);
|
|
|
|
glm_rotate_make(rot, *rotation, up);
|
|
|
|
glm_mat4_mulv3(rot, forward, 1.0f, dir);
|
|
|
|
glm_mat4_mulv3(rot, forward, 1.0f, dir);
|
|
|
|
|
|
|
|
|
|
|
|
vec3 movement_rot;
|
|
|
|
vec3 movement_rot;
|
|
|
@ -1793,7 +1793,7 @@ VkResult update_ubo(void** buffers, uint32_t frame_index) {
|
|
|
|
glm_vec3_add(movement_rot, world_position, world_position);
|
|
|
|
glm_vec3_add(movement_rot, world_position, world_position);
|
|
|
|
|
|
|
|
|
|
|
|
struct SceneUBO ubo = {};
|
|
|
|
struct SceneUBO ubo = {};
|
|
|
|
glm_perspective(90.0f, 800.0/600.0, 0.1, 100, ubo.proj);
|
|
|
|
glm_perspective(90.0f, aspect_ratio, 0.1, 100, ubo.proj);
|
|
|
|
glm_look(world_position, dir, up, ubo.view);
|
|
|
|
glm_look(world_position, dir, up, ubo.view);
|
|
|
|
|
|
|
|
|
|
|
|
memcpy(buffers[frame_index], (void*)&ubo, sizeof(ubo));
|
|
|
|
memcpy(buffers[frame_index], (void*)&ubo, sizeof(ubo));
|
|
|
@ -1802,7 +1802,7 @@ VkResult update_ubo(void** buffers, uint32_t frame_index) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VkResult draw_frame(VulkanContext* context) {
|
|
|
|
VkResult draw_frame(VulkanContext* context) {
|
|
|
|
update_ubo(context->scene_ubo_ptrs, context->current_frame);
|
|
|
|
update_scene_ubo(context->scene_ubo_ptrs, context->current_frame, world_position, &rotation, (float)context->swapchain_extent.width/(float)context->swapchain_extent.height, 0.01);
|
|
|
|
|
|
|
|
|
|
|
|
VkResult result;
|
|
|
|
VkResult result;
|
|
|
|
result = vkWaitForFences(context->device, 1, &context->in_flight_fences[context->current_frame], VK_TRUE, UINT64_MAX);
|
|
|
|
result = vkWaitForFences(context->device, 1, &context->in_flight_fences[context->current_frame], VK_TRUE, UINT64_MAX);
|
|
|
|