Add movement relative to time
Previously movement was based on frames rather than time. I added time_get_dt() function for getting time since last frame and changed rotation speed to use this function. Signed-off-by: Piotr Krygier <piotrkrygier@everyonecancode@xyz>
This commit is contained in:
@@ -28,7 +28,6 @@ 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};
|
||||
@@ -38,6 +37,7 @@ static void model_view_projection_update(struct graphics_context_t* context)
|
||||
float fovy;
|
||||
float z_near;
|
||||
float z_far;
|
||||
static float rotation = 0.0;
|
||||
|
||||
eye[2] = -5.0f;
|
||||
|
||||
@@ -49,7 +49,7 @@ static void model_view_projection_update(struct graphics_context_t* context)
|
||||
|
||||
glm_mat4_identity(context->mvp_data.model);
|
||||
|
||||
glm_rotate(context->mvp_data.model, time_get_sec_from_start() * glm_rad(90.0f), rotation_vec);
|
||||
glm_rotate(context->mvp_data.model, rotation, rotation_vec);
|
||||
glm_lookat(eye, center, up, context->mvp_data.view);
|
||||
glm_perspective(
|
||||
fovy,
|
||||
@@ -57,6 +57,8 @@ static void model_view_projection_update(struct graphics_context_t* context)
|
||||
z_near,
|
||||
z_far,
|
||||
context->mvp_data.proj);
|
||||
|
||||
rotation += time_get_dt() * glm_rad(90.0);
|
||||
}
|
||||
|
||||
static rse_err_t render_static_mesh(struct graphics_context_t* context, uint32_t renderer_id)
|
||||
|
||||
Reference in New Issue
Block a user