Add scene time based rotation
Added time based scene rotation as a proof of concept. Based on this implementation, I can not only move scene using external data (like mouse, in the future) but also I can use provided functionality to get high resolution timer for future use Signed-off-by: Piotr Krygier <piotrkrygier@everyonecancode@xyz>
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <vulkan/vulkan_core.h>
|
||||
|
||||
#include "descriptor_builder.h"
|
||||
@@ -28,15 +29,19 @@ struct rse_graphics_context_t
|
||||
struct graphics_context_t* context;
|
||||
};
|
||||
|
||||
#define NS_TO_S(time) (time/1000000000)
|
||||
static void model_view_projection_update(struct graphics_context_t* context)
|
||||
{
|
||||
vec3 eye = {0};
|
||||
vec3 center = {0};
|
||||
vec3 up = {0};
|
||||
vec3 rotation_vec = {1.0f, 0.0f, 0.0f};
|
||||
vec3 rotation_vec = {0.0f, 0.0f, 1.0f};
|
||||
float fovy;
|
||||
float z_near;
|
||||
float z_far;
|
||||
double diff_time = 0.0;
|
||||
struct timespec now = {0};
|
||||
static struct timespec last_time = {0};
|
||||
|
||||
eye[2] = -5.0f;
|
||||
|
||||
@@ -46,9 +51,17 @@ static void model_view_projection_update(struct graphics_context_t* context)
|
||||
z_near = 0.1f;
|
||||
z_far = 20.0f;
|
||||
|
||||
if (last_time.tv_nsec == 0) {
|
||||
timespec_get(&last_time, TIME_UTC);
|
||||
}
|
||||
|
||||
timespec_get(&now, TIME_UTC);
|
||||
|
||||
diff_time = NS_TO_S((double)(now.tv_nsec - last_time.tv_nsec)) + (now.tv_sec - last_time.tv_sec);
|
||||
|
||||
glm_mat4_identity(context->mvp_data.model);
|
||||
|
||||
glm_rotate(context->mvp_data.model, glm_rad(0.0f), rotation_vec);
|
||||
glm_rotate(context->mvp_data.model, diff_time * glm_rad(90.0f), rotation_vec);
|
||||
glm_lookat(eye, center, up, context->mvp_data.view);
|
||||
glm_perspective(
|
||||
fovy,
|
||||
|
||||
Reference in New Issue
Block a user