Raftel Engine
 
Loading...
Searching...
No Matches
camera.hpp
1#ifndef __CAMERA_H__
2#define __CAMERA_H__ 1
3
4#include <raftel/global_macros.hpp>
5#include <glm/mat4x4.hpp>
6#include <memory>
7#include <glm/gtc/quaternion.hpp>
8#include "raftel/input.hpp"
9
10struct GLFWwindow;
11
12namespace Raftel {
13
14 class Window;
15 class ShaderProgram;
19 enum class CameraState {
20 Normal,
21 Possessed
22 };
23
27 class Camera {
28 public:
34
39 float getMovementSpeed() const;
40
45 glm::vec3 getPosition() const;
46
51 glm::vec3 getRotation() const;
52
57 glm::mat4 getViewMatrix() const;
58
63 glm::mat4 getProjectionMatrix() const;
64
69 void SetPosition(const glm::vec3& position);
70
75 void SetRotation(const glm::vec3& rotation);
76
81 void Update(const std::unique_ptr<Window>& window);
82
88
93 void Translate(const glm::vec3& translation);
99 void Rotate(float angle, const glm::vec3& axis);
100
106 void SetState(CameraState newState, GLFWwindow* window);
107
112 CameraState GetState() const;
113
120
127
135 void ChangeSpeedWithKey(Raftel::Window* window, Raftel::Input::Keys key_,float fastSpeed = 5.0f, float normalSpeed = 2.0f);
136
142 void ChangeSpeedWithScroll(Raftel::Window* window, float speedOffset);
143
149
150 private:
151 std::unique_ptr<Raftel::Input> input;
152
153 glm::mat4 transform;
154 glm::mat4 projection;
155 glm::mat4 view;
156
157 float near;
158 float far;
159 float aspectRatio;
160 float FOV;
161
162 glm::vec3 inputMovement;
163 glm::vec3 inputRotation;
164
165 float movementSpeed;
166 float rotationSpeed;
167
168 CameraState state;
169 glm::quat orientation = glm::quat(1.0, 0.0, 0.0, 0.0);
170
171 glm::vec3 cameraPosition;
172 float yawAngle = 0.0f;
173 float pitchAngle = 0.0f;
174 };
175}
176#endif
void ChangeSpeedWithKey(Raftel::Window *window, Raftel::Input::Keys key_, float fastSpeed=5.0f, float normalSpeed=2.0f)
Changes camera movement speed when a specific key is pressed.
Camera(Raftel::Window *w)
Constructs a Camera object.
glm::vec3 getPosition() const
Gets the current position of the camera.
void Translate(const glm::vec3 &translation)
Moves the camera by a given translation vector.
float getMovementSpeed() const
Gets the current movement speed of the camera.
void Update(const std::unique_ptr< Window > &window)
Updates the camera's transformation matrices.
glm::mat4 getViewMatrix() const
Gets the view matrix of the camera.
void setUniforms(ShaderProgram &prg)
Sets shader uniforms related to the camera.
void SetState(CameraState newState, GLFWwindow *window)
Sets the camera state.
void SetPosition(const glm::vec3 &position)
Sets the position of the camera.
void SetRotation(const glm::vec3 &rotation)
Sets the rotation of the camera.
void ToggleState(Raftel::Window *window, Raftel::Input::Keys key_)
Toggles the camera state using a keyboard key.
CameraState GetState() const
Gets the current camera state.
void PossessedInput(Raftel::Window *window)
Processes user input when the camera is in possessed mode.
void ChangeSpeedWithScroll(Raftel::Window *window, float speedOffset)
Adjusts camera movement speed using mouse scroll input.
glm::vec3 getRotation() const
Gets the current rotation of the camera.
void ToggleState(Raftel::Window *window, Raftel::Input::Buttons button_)
Toggles the camera state using a mouse button.
void Rotate(float angle, const glm::vec3 &axis)
Rotates the camera around an axis.
glm::mat4 getProjectionMatrix() const
Gets the projection matrix of the camera.
Keys
Enumeration of keyboard keys.
Definition input.hpp:33
Buttons
Enumeration of mouse buttons.
Definition input.hpp:22
A class to represent an OpenGL shader program, combining vertex and fragment shaders.
Definition shader.hpp:119
Represents a single window in the system, supporting OpenGL context and input handling.
Definition window.hpp:84