-
Notifications
You must be signed in to change notification settings - Fork 3
/
PerspectiveCamera.hpp
120 lines (103 loc) · 3.67 KB
/
PerspectiveCamera.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#ifndef CSCI441_PERSPECTIVE_CAMERA_HPP
#define CSCI441_PERSPECTIVE_CAMERA_HPP
#include "Camera.hpp"
namespace CSCI441 {
/**
* @brief Abstract Class to represent a perspective camera. Stores aspect ratio and field of view
*/
class PerspectiveCamera : public CSCI441::Camera {
public:
/**
* @brief initializes the Perspective Camera
* @param aspectRatio aspect ratio of view plane (defaults to 1.0f)
* @param fovy vertical field of view (defaults to 45.0f)
* @param nearClipPlane near z clip plane (defaults to 0.001f)
* @param farClipPlane far z clip plane (defaults to 1000.0f)
* @note field of view specified in degrees
*/
explicit PerspectiveCamera(GLfloat aspectRatio = 1.0f, GLfloat fovy = 45.0f, GLfloat nearClipPlane = 0.001f, GLfloat farClipPlane = 1000.0f);
/**
* @brief updates the camera's aspect ratio
* @param aspectRatio new aspect ratio to apply to camera
* @note internally updates the camera's projection matrix
*/
[[maybe_unused]] virtual void setAspectRatio(GLfloat aspectRatio) final;
/**
* @brief updates the camera's vertical field of view
* @param fovy new vertical field of view to apply to camera
* @note internally updates the camera's projection matrix
*/
[[maybe_unused]] virtual void setVerticalFOV(GLfloat fovy) final;
/**
* @brief updates the camera's near clip plane
* @param near new near clip plane to apply to camera
* @note internally updates the camera's projection matrix
*/
[[maybe_unused]] virtual void setNearClipPlane(GLfloat near) final;
/**
* @brief updates the camera's far clip plane
* @param far new far clip plane to apply to camera
* @note internally updates the camera's projection matrix
*/
[[maybe_unused]] virtual void setFarClipPlane(GLfloat far) final;
protected:
/**
* @brief computes the perspective projection matrix for the camera
*/
void mUpdateProjectionMatrix();
private:
/**
* @brief vertical field of view
* @note stored in degrees
*/
GLfloat _fovy;
/**
* @brief aspect ratio of view plane
*/
GLfloat _aspectRatio;
/**
* @brief near Z clipping plane
*/
GLfloat _nearClipPlane;
/**
* @brief far Z clipping plane
*/
GLfloat _farClipPlane;
};
}
inline CSCI441::PerspectiveCamera::PerspectiveCamera(
const GLfloat aspectRatio,
const GLfloat fovy,
const GLfloat nearClipPlane,
const GLfloat farClipPlane
) : _fovy(fovy),
_aspectRatio(aspectRatio),
_nearClipPlane(nearClipPlane),
_farClipPlane(farClipPlane)
{
mUpdateProjectionMatrix();
}
[[maybe_unused]]
inline void CSCI441::PerspectiveCamera::setAspectRatio(GLfloat aspectRatio) {
_aspectRatio = aspectRatio;
mUpdateProjectionMatrix();
}
[[maybe_unused]]
inline void CSCI441::PerspectiveCamera::setVerticalFOV(GLfloat fovy) {
_fovy = fovy;
mUpdateProjectionMatrix();
}
[[maybe_unused]]
inline void CSCI441::PerspectiveCamera::setNearClipPlane(GLfloat near) {
_nearClipPlane = near;
mUpdateProjectionMatrix();
}
[[maybe_unused]]
inline void CSCI441::PerspectiveCamera::setFarClipPlane(GLfloat far) {
_farClipPlane = far;
mUpdateProjectionMatrix();
}
inline void CSCI441::PerspectiveCamera::mUpdateProjectionMatrix() {
mProjectionMatrix = glm::perspective(_fovy, _aspectRatio, _nearClipPlane, _farClipPlane);
}
#endif//CSCI441_PERSPECTIVE_CAMERA_HPP