Rendu
A lightweight rendering engine for experimentations
Loading...
Searching...
No Matches
Camera.hpp
1#pragma once
2
3#include "system/Codable.hpp"
4#include "Common.hpp"
5
11class Camera {
12
13public:
15 Camera();
16
22 virtual void pose(const glm::vec3 & position, const glm::vec3 & center, const glm::vec3 & up);
23
30 virtual void projection(float ratio, float fov, float near, float far);
31
36 void frustum(float near, float far);
37
41 void ratio(float ratio);
42
46 void fov(float fov);
47
54 void pixelShifts(glm::vec3 & corner, glm::vec3 & dx, glm::vec3 & dy) const;
55
60 float fov() const { return _fov; }
61
66 float ratio() const { return _ratio; }
67
72 const glm::mat4 & view() const { return _view; }
73
78 const glm::mat4 & projection() const { return _projection; }
79
84 const glm::vec3 & position() const { return _eye; }
85
90 const glm::vec3 & up() const { return _up; }
91
96 const glm::vec3 & center() const { return _center; }
97
102 const glm::vec3 direction() const { return glm::normalize(_center - _eye); }
103
108 const glm::vec2 & clippingPlanes() const { return _clippingPlanes; }
109
113 void apply(const Camera & camera);
114
128 bool decode(const KeyValues & params);
129
133 KeyValues encode() const;
134
136 virtual ~Camera() = default;
137
139 Camera(const Camera &) = default;
140
144 Camera & operator=(const Camera &) = default;
145
147 Camera(Camera &&) = default;
148
152 Camera & operator=(Camera &&) = default;
153
154protected:
156 void updateProjection();
157
159 void updateView();
160
161 glm::mat4 _view = glm::mat4(1.0f);
162 glm::mat4 _projection = glm::mat4(1.0f);
163
164 // Vectors defining the view frame.
165 glm::vec3 _eye = glm::vec3(0.0, 0.0, 1.0);
166 glm::vec3 _center = glm::vec3(0.0, 0.0, 0.0);
167 glm::vec3 _up = glm::vec3(0.0, 1.0, 0.0);
168 glm::vec3 _right = glm::vec3(1.0, 0.0, 0.0);
169
170 glm::vec2 _clippingPlanes = glm::vec2(0.01f, 100.0f);
171
172 float _fov = 1.3f;
173 float _ratio = 1.0f;
174};
This class represents a camera as used in real-time rendering APIs. It provides a view and projection...
Definition: Camera.hpp:11
Camera()
Constructor.
Definition: Camera.cpp:5
float fov() const
Definition: Camera.hpp:60
glm::vec3 _eye
The camera position.
Definition: Camera.hpp:165
const glm::mat4 & projection() const
Definition: Camera.hpp:78
float _ratio
The aspect ratio.
Definition: Camera.hpp:173
Camera(const Camera &)=default
Camera & operator=(const Camera &)=default
Camera(Camera &&)=default
glm::vec3 _up
The camera up vector.
Definition: Camera.hpp:167
void updateProjection()
Update the projection matrix using the camera parameters.
Definition: Camera.cpp:51
bool decode(const KeyValues &params)
Definition: Camera.cpp:66
glm::vec3 _right
The camera right vector.
Definition: Camera.hpp:168
glm::mat4 _projection
The projection matrix.
Definition: Camera.hpp:162
glm::mat4 _view
The view matrix.
Definition: Camera.hpp:161
glm::vec2 _clippingPlanes
The near and far plane distances.
Definition: Camera.hpp:170
Camera & operator=(Camera &&)=default
const glm::vec2 & clippingPlanes() const
Definition: Camera.hpp:108
void pixelShifts(glm::vec3 &corner, glm::vec3 &dx, glm::vec3 &dy) const
Definition: Camera.cpp:42
float ratio() const
Definition: Camera.hpp:66
void updateView()
Update the view matrix using the camera position and orientation.
Definition: Camera.cpp:56
const glm::vec3 & up() const
Definition: Camera.hpp:90
glm::vec3 _center
The camera center (look-at point)
Definition: Camera.hpp:166
const glm::vec3 & center() const
Definition: Camera.hpp:96
const glm::vec3 & position() const
Definition: Camera.hpp:84
virtual void pose(const glm::vec3 &position, const glm::vec3 &center, const glm::vec3 &up)
Definition: Camera.cpp:10
virtual ~Camera()=default
void frustum(float near, float far)
Definition: Camera.cpp:27
float _fov
The vertical field of view, in radians.
Definition: Camera.hpp:172
const glm::vec3 direction() const
Definition: Camera.hpp:102
const glm::mat4 & view() const
Definition: Camera.hpp:72
KeyValues encode() const
Definition: Camera.cpp:109
void apply(const Camera &camera)
Definition: Camera.cpp:60
Represent a key-values tuple.
Definition: Config.hpp:9