Zen 0.3.0
Loading...
Searching...
No Matches
ZEN_Camera.h
1#pragma once
2
3#include <zen/zen_pch.h>
4
5namespace Zen {
6 enum CameraType : uint8_t {
7 Orthographic = 1,
8 Perspective = 2,
9 };
10
11 class Camera {
12 public:
13 Camera(CameraType type = CameraType::Orthographic);
14 ~Camera() = default;
15
16 void setCameraType(CameraType type);
17
18 void setPerspective(float fov, float aspect, float near, float far);
19 void setOrthographic(float left, float right, float bottom, float top);
20
21 void setAspectRatio(float aspect);
22 void setClip(float near, float far);
23
24 void setPosition(const glm::vec3 &position);
25 void setRotation(float yaw, float pitch, float roll);
26
27 void setSpeed(float speed);
28 void setSensitivity(float sensitivity);
29
30 CameraType type() const;
31 const glm::vec3 &position() const;
32 glm::vec3 rotation() const;
33 float speed() const;
34 float sensitivity() const;
35 float aspectRatio() const;
36
37 const glm::mat4 &projectionMatrix() const;
38 const glm::mat4 &viewMatrix() const;
39 glm::mat4 viewProjectionMatrix() const;
40
41 private:
42 void updateProjection();
43 void updateView();
44 void updateDirection();
45 void clampPitch();
46
47 CameraType m_cameraType;
48
49 glm::vec3 m_position = {0.0f, 0.0f, 0.0f};
50 glm::vec3 m_front = {0.0f, 0.0f, -1.0f};
51 glm::vec3 m_up = {0.0f, 1.0f, 0.0f};
52 glm::vec3 m_right = {1.0f, 0.0f, 0.0f};
53 glm::vec3 m_worldUp = {0.0f, 1.0f, 0.0f};
54
55 // glm::vec3 m_focalPoint = {0.0f, 0.0f, 0.0f}; // maybe when I have orbit or pan
56
57 glm::mat4 m_projection{1.0f};
58 glm::mat4 m_view{1.0f};
59
60 float m_yaw = -90.0f;
61 float m_pitch = 0.0f;
62 float m_roll = 0.0f;
63
64 float m_fov = 45.0f;
65 float m_aspectRatio = 16.0f / 9.0f; // 16:9
66 float m_near = 0.1f;
67 float m_far = 1000.0f;
68
69 float m_orthoLeft{-10.0f};
70 float m_orthoRight{+10.0f};
71 float m_orthoBottom{-10.0f};
72 float m_orthoTop{+10.0f};
73
74 float m_cameraSpeed = 1.5f;
75 float m_cameraSensitivity = 0.1f;
76 };
77} // namespace Zen