hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/src/core/camera.h
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2025-08-12 18:41:26 +0200
committerhachem <im@hachem.wtf>2025-08-12 18:41:26 +0200
commit7e06a916e6a385c37075abcb83d14b8c1fef7bc0 (patch)
tree8054d96e89d43b0f98b75af726079d723a70ca2a /src/core/camera.h
parent50cdd344a3ed87c75a67739e2ffd34762e9b0895 (diff)
feat: camera
Diffstat (limited to 'src/core/camera.h')
-rw-r--r--src/core/camera.h69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/core/camera.h b/src/core/camera.h
new file mode 100644
index 0000000..200c4b0
--- /dev/null
+++ b/src/core/camera.h
@@ -0,0 +1,69 @@
+#pragma once
+
+#include <glm/glm.hpp>
+#include <glm/gtc/matrix_transform.hpp>
+
+namespace Donut
+{
+ class Camera
+ {
+ public:
+ Camera(float fov = 45.0f, float aspect_ratio = 16.0f / 9.0f,
+ float near_plane = 0.1f, float far_plane = 100.0f);
+ ~Camera() = default;
+
+ void set_position(const glm::vec3& position) { m_position = position; recalculate_view_matrix(); }
+ void set_rotation(const glm::vec3& rotation) { m_rotation = rotation; recalculate_view_matrix(); }
+
+ const glm::vec3& get_position() const { return m_position; }
+ const glm::vec3& get_rotation() const { return m_rotation; }
+
+ glm::vec3 get_forward_direction() const;
+ glm::vec3 get_right_direction() const;
+ glm::vec3 get_up_direction() const;
+
+ const glm::mat4& get_projection_matrix() const { return m_projection_matrix; }
+ const glm::mat4& get_view_matrix() const { return m_view_matrix; }
+ const glm::mat4& get_view_projection_matrix() const { return m_view_projection_matrix; }
+
+ void set_projection(float fov, float aspect_ratio, float near_plane, float far_plane);
+
+ void on_update(float delta_time);
+ void on_mouse_move(float x_offset, float y_offset, bool constrain_pitch = true);
+
+ void move_forward(float delta_time);
+ void move_backward(float delta_time);
+ void move_right(float delta_time);
+ void move_left(float delta_time);
+ void move_up(float delta_time);
+ void move_down(float delta_time);
+
+ void set_mouse_sensitivity(float sensitivity) { m_mouse_sensitivity = sensitivity; }
+ float get_mouse_sensitivity() const { return m_mouse_sensitivity; }
+
+ void set_movement_speed(float speed) { m_movement_speed = speed; }
+ float get_movement_speed() const { return m_movement_speed; }
+
+ private:
+ void recalculate_view_matrix();
+ void recalculate_projection_matrix();
+ private:
+ glm::mat4 m_projection_matrix;
+ glm::mat4 m_view_matrix;
+ glm::mat4 m_view_projection_matrix;
+
+ glm::vec3 m_position = { 0.0f, 0.0f, 3.0f };
+ glm::vec3 m_rotation = { 0.0f, 0.0f, 0.0f };
+
+ float m_fov = 45.0f;
+ float m_aspect_ratio = 16.0f / 9.0f;
+ float m_near_plane = 0.1f;
+ float m_far_plane = 100.0f;
+
+ float m_mouse_sensitivity = 0.1f;
+ float m_movement_speed = 5.0f;
+ bool m_first_mouse = true;
+ float m_last_x = 0.0f;
+ float m_last_y = 0.0f;
+ };
+}