VoxelEngine
 
Loading...
Searching...
No Matches
Camera.h
1#pragma once
2
3#include <array>
4#include <glm/glm.hpp>
5#include <glm/gtc/quaternion.hpp>
6
7#include "../Globals.h"
8#include "physics/Plane.h"
9#include "render/events/EngineEventSite.h"
10
11
12namespace engine {
13
15 float zNear = 0.1f;
16 float zFar = 1200.0f;
17 };
18
19 struct OrthoOptions : public CameraOptions {
20 float width;
21 float height;
22 };
23
25 float fov;
26 float aspectRatio;
27 };
28
29 class Camera : public EngineEventSite {
30 public:
31 enum class ProjectionType {
32 Perspective,
33 Orthographic
34 };
35
36 Camera(OrthoOptions opts);
38
39 void windowResizeEvent(ResizeEvent* ev) override;
40
41 void position(const glm::vec3& pos) { m_position = pos; }
42 const glm::vec3& position() const { return m_position; }
43 const glm::vec3& lookDirection() const { return m_front; }
44
48 glm::quat rotation(bool ignorePitch) const;
49
50 void lookAt(const glm::vec3& target);
51 void lookDirection(const glm::vec3& direction);
52
53 void rotate(float dx, float dy, bool constrainPitch = true);
54 void resize(int width, int height);
55
56 glm::mat4 getView() const;
57 glm::mat4 getProjection() const { return m_projection; };
58
59 float farPlane() const { return m_zFar; }
60 float nearPlane() const { return m_zNear; }
61 float fov() const { return m_fov; }
62 float aspectRatio() const { return m_aspectRatio; }
63
66 std::array<Plane, 6> getFrustum() const;
73 std::array<glm::vec3, 8> getFrustumCorners() const;
74
75 static std::array<glm::vec3, 8> getFrustumCorners(
76 const glm::mat4& projection, const glm::mat4& view
77 );
78
79 protected:
80 glm::vec3 m_worldUp = UP;
81
82 float m_yaw, m_pitch;
83 glm::vec3 m_position;
84 glm::vec3 m_front;
85 glm::vec3 m_up;
86 glm::vec3 m_right;
87
88 glm::mat4 m_projection;
89 ProjectionType m_type;
90
91 float m_fov = 0.0f;
92 float m_zNear = 0.1f;
93 float m_zFar = 1200.0f;
94 float m_aspectRatio = 1.0f;
95
96 void updateVectors();
97 };
98} // namespace engine
Definition Camera.h:29
glm::quat rotation(bool ignorePitch) const
Returns the camera's rotation as a quaternion.
Definition Camera.cpp:105
std::array< Plane, 6 > getFrustum() const
Returns the camera's frustum in world space.
Definition Camera.cpp:82
std::array< glm::vec3, 8 > getFrustumCorners() const
Returns the camera's frustum corners in world space.
Definition Camera.cpp:101
Definition EngineEventSite.h:8
Definition Camera.h:14
Definition Camera.h:19
Definition Camera.h:24
Definition EngineEvents.h:6