>>102750322
needs the cglm library
#include <cglm/cglm.h>
void mouse_look(double x, double y, float delta_time) {
if (first_mouse) {
last_x = x;
last_y = y;
first_mouse = 0;
}
double x_offset = x - last_x;
double y_offset = y - last_y;
last_x = x;
last_y = y;
float sensitivity = 0.1f;
x_offset *= sensitivity;
y_offset *= sensitivity;
yaw += x_offset;
pitch += y_offset;
if (pitch > 89.0f) {
pitch = 89.0f;
}
if (pitch < -89.0f) {
pitch = -89.0f;
}
// Create quaternion from Euler angles
versor q_pitch, q_yaw, q_roll, q;
glm_quatv(q_pitch, glm_rad(pitch), (vec3){1.0f, 0.0f, 0.0f});
glm_quatv(q_yaw, glm_rad(yaw), (vec3){0.0f, 1.0f, 0.0f});
glm_quatv(q_roll, glm_rad(0.0f), (vec3){0.0f, 0.0f, 1.0f});
glm_quat_mul(q_yaw, q_pitch, q);
glm_quat_mul(q, q_roll, q);
// Rotate the forward vector by the quaternion
vec3 direction = {0.0f, 0.0f, -1.0f};
glm_quat_rotatev(q, direction, direction);
glm_vec3_normalize_to(direction, camera.forward);
// Build new right direction from new forward direction
glm_vec3_cross(camera.up, camera.forward, camera.right);
glm_vec3_normalize(camera.right);
vec3 cam_target;
glm_vec3_add(camera.position, camera.forward, cam_target);
glm_lookat(camera.position, cam_target, camera.up, vk_context.view);
vk_write_to_device(&vk_context.device, &vk_context.transform_ssbo_memory, &vk_context.view, 0, sizeof(mat4), 0);
}