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:
@@ -2,15 +2,11 @@
|
||||
#define CAMERA_H
|
||||
|
||||
#include "cglm/struct/vec3.h"
|
||||
#include "cglm/types-struct.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
// TODO: Use mat4s instead of vec3s for position, forward, up and right
|
||||
vec3s position;
|
||||
vec3s forward;
|
||||
vec3s up;
|
||||
vec3s right;
|
||||
versors rotation;
|
||||
|
||||
float focal_length;
|
||||
float size_x;
|
||||
@@ -21,6 +17,6 @@ typedef struct
|
||||
float fov_y;
|
||||
} camera_t;
|
||||
|
||||
camera_t camera_create(vec3s position, vec3s forward, vec3s up, float focal_length, float size_x, float aspect_ratio);
|
||||
camera_t camera_create(vec3s position, versors rotation, float focal_length, float size_x, float aspect_ratio);
|
||||
|
||||
#endif // CAMERA_H
|
||||
|
||||
Reference in New Issue
Block a user