Botcraft 1.21.4
Loading...
Searching...
No Matches
Camera.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <glad/glad.h>
4#include <glm/glm.hpp>
5#include <glm/gtc/matrix_transform.hpp>
6
7#include <array>
8
9namespace Botcraft
10{
11 namespace Renderer
12 {
13 // A camera class that keep position and orientation and calculates the corresponding matrices for OpenGL
14 class Camera
15 {
16 public:
17 // Constructor
18 Camera(glm::vec3 position_ = glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3 up_ = glm::vec3(0.0f, 1.0f, 0.0f), float yaw_ = 0.0f, float pitch_ = 0.0f);
19
20 // Getter
21 const glm::mat4& GetViewMatrix() const;
22 const glm::vec3& GetPosition() const;
23 const glm::vec3& GetFront() const;
24 const std::array<glm::vec4, 6>& GetFrustumPlanes() const;
25 float GetYaw() const;
26 float GetPitch() const;
27
28 // Setter
29 void SetPosition(const float x, const float y, const float z);
30 void SetRotation(const float pitch_, const float yaw_);
31 void SetProjection(const glm::mat4& projection);
32
33 bool GetHasChangedPosition() const;
34 bool GetHasChangedOrientation() const;
35
38
39 // Returns the distance between coordinates and the camera
40 float GetDistance(const float x_, const float y_, const float z_) const;
41
42 private:
43 // Compute the view matrix from camera parameters
45
46 // Compute frustum planes from camera parameters
48
49 private:
50 glm::vec3 worldUp;
51
52 // Camera position
53 glm::vec3 position;
54 glm::vec3 front;
55
56 // Camera orientation
57 float yaw;
58 float pitch;
59
60 // Matrices
62 glm::mat4 view_matrix;
63
64 // Frustum planes
65 std::array<glm::vec4, 6> frustum;
66
69 };
70 } // Renderer
71} // Botcraft
float GetPitch() const
Definition Camera.cpp:58
void SetPosition(const float x, const float y, const float z)
Definition Camera.cpp:30
bool GetHasChangedPosition() const
Definition Camera.cpp:85
const std::array< glm::vec4, 6 > & GetFrustumPlanes() const
Definition Camera.cpp:48
const glm::vec3 & GetFront() const
Definition Camera.cpp:43
void SetRotation(const float pitch_, const float yaw_)
Definition Camera.cpp:63
const glm::vec3 & GetPosition() const
Definition Camera.cpp:38
const glm::mat4 & GetViewMatrix() const
Definition Camera.cpp:16
float GetDistance(const float x_, const float y_, const float z_) const
Definition Camera.cpp:21
std::array< glm::vec4, 6 > frustum
Definition Camera.hpp:65
void SetProjection(const glm::mat4 &projection)
Definition Camera.cpp:79
bool GetHasChangedOrientation() const
Definition Camera.cpp:90