Refactor camera system to use quaternion rotations

Added quaternion and vector structures from the cglm library for handling 3D rotations and directions.
Added a new function `euler_to_quat` to convert Euler angles to a quaternion representation.
Changed the `camera_t` structure to replace separate forward, up, and right vectors with a single rotation quaternion.
Changed the `camera_create` function to accept a rotation quaternion instead of separate direction vectors.
Changed the `scene_init` function to initialize the camera with a default rotation quaternion.
Changed the `ensure_camera_aspect_ratio` function to maintain the camera's rotation quaternion.
Changed the `screen_render_pixel`, `scene_render_tile`, and `scene_render` functions to compute camera coordinates based on the quaternion rotation.
This commit is contained in:
2025-04-22 17:26:04 +09:00
parent e49004e6a2
commit 9cc420693c
5 changed files with 38 additions and 27 deletions

View File

@@ -58,7 +58,7 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,
}
scene.camera.position = (vec3s){-7.5f, 2.0f, 0.0f};
scene.camera.forward = glms_vec3_normalize((vec3s){1.0f, 0.0f, 0.0f});
scene.camera.rotation = euler_to_quat(10.0f, -90.0f, 0.0f);
light_entity_t sun = light_create_directional_light(&scene.lights);
directional_light_t* sun_light = &scene.lights.directional_lights[sun.id];