coral_camera.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #pragma once
  2. // LIBS
  3. #define GLM_FORCE_RADIANS
  4. #define GLM_FORCE_DEPTH_ZERO_TO_ONE
  5. #include <glm.hpp>
  6. #include <GLFW/glfw3.h>
  7. namespace coral_3d
  8. {
  9. struct KeyBindings
  10. {
  11. int move_forward = GLFW_KEY_W;
  12. int move_backward = GLFW_KEY_S;
  13. int move_left = GLFW_KEY_A;
  14. int move_right = GLFW_KEY_D;
  15. int move_up = GLFW_KEY_E;
  16. int move_down = GLFW_KEY_Q;
  17. int sprint = GLFW_KEY_LEFT_SHIFT;
  18. };
  19. class coral_camera final
  20. {
  21. public:
  22. coral_camera(glm::vec3 position, float movement_speed = 3.f, float mouse_sensitivity = 0.1f);
  23. ~coral_camera() = default;
  24. void set_orthographic_projection(
  25. float left, float right, float top, float bottom, float near, float far);
  26. void set_perspective_projection(float fovy, float aspect, float near, float far);
  27. void set_view_direction(glm::vec3 position, glm::vec3 direction, glm::vec3 up = glm::vec3{ 0.f, -1.f, 0.f });
  28. void set_view_target(glm::vec3 position, glm::vec3 target, glm::vec3 up = glm::vec3{ 0.f, -1.f, 0.f });
  29. void set_view_yxz(glm::vec3 position, glm::vec3 rotation);
  30. const glm::mat4& get_projection() const { return projection_matrix_; }
  31. const glm::mat4& get_view() const { return view_matrix_; }
  32. const glm::vec3& get_position() const { return position_; }
  33. void update_input(GLFWwindow* pWindow, float dt);
  34. private:
  35. void update_camera_vectors();
  36. KeyBindings keys_{};
  37. // Camera frame
  38. glm::vec3 position_{};
  39. glm::vec3 forward_{};
  40. glm::vec3 right_{};
  41. glm::vec3 up_{};
  42. glm::vec3 world_up_{0.f, 1.f, 0.f};
  43. // Mouse
  44. float last_mouse_x_{};
  45. float last_mouse_y_{};
  46. // Rotation
  47. float yaw_{0.f};
  48. float pitch_{0.f};
  49. float movement_speed_{ 8.f };
  50. float sprint_movement_speed_{ 14.f };
  51. float mouse_sensitivity_{ 1.5f };
  52. glm::mat4 projection_matrix_{ 1.f };
  53. glm::mat4 view_matrix_{0.1f};
  54. };
  55. }