CSCI441 OpenGL Library 5.17.0
CS@Mines CSCI441 Computer Graphics Course Library
Loading...
Searching...
No Matches
PerspectiveCamera.hpp
Go to the documentation of this file.
1
12#ifndef CSCI441_PERSPECTIVE_CAMERA_HPP
13#define CSCI441_PERSPECTIVE_CAMERA_HPP
14
15#include "Camera.hpp"
16
17namespace CSCI441 {
18
23 public:
32 explicit PerspectiveCamera(GLfloat aspectRatio = 1.0f, GLfloat fovy = 45.0f, GLfloat nearClipPlane = 0.001f, GLfloat farClipPlane = 1000.0f);
33
37 ~PerspectiveCamera() override = default;
38
44 [[maybe_unused]] virtual void setAspectRatio(GLfloat aspectRatio) final;
45
51 [[maybe_unused]] virtual void setVerticalFOV(GLfloat fovy) final;
52
58 [[maybe_unused]] virtual void setNearClipPlane(GLfloat near) final;
59
65 [[maybe_unused]] virtual void setFarClipPlane(GLfloat far) final;
66
67 protected:
72
82
92
93 private:
98 GLfloat _fovy;
102 GLfloat _aspectRatio;
106 GLfloat _nearClipPlane;
110 GLfloat _farClipPlane;
111 };
112
113}
114
116 const GLfloat aspectRatio,
117 const GLfloat fovy,
118 const GLfloat nearClipPlane,
119 const GLfloat farClipPlane
120) : _fovy(fovy),
121 _aspectRatio(aspectRatio),
122 _nearClipPlane(nearClipPlane),
123 _farClipPlane(farClipPlane)
124{
126}
127
128[[maybe_unused]]
129inline void CSCI441::PerspectiveCamera::setAspectRatio(const GLfloat aspectRatio) {
130 _aspectRatio = aspectRatio;
131 mUpdateProjectionMatrix();
132}
133
134[[maybe_unused]]
135inline void CSCI441::PerspectiveCamera::setVerticalFOV(const GLfloat fovy) {
136 _fovy = fovy;
137 mUpdateProjectionMatrix();
138}
139
140[[maybe_unused]]
141inline void CSCI441::PerspectiveCamera::setNearClipPlane(const GLfloat near) {
142 _nearClipPlane = near;
143 mUpdateProjectionMatrix();
144}
145
146[[maybe_unused]]
147inline void CSCI441::PerspectiveCamera::setFarClipPlane(const GLfloat far) {
148 _farClipPlane = far;
149 mUpdateProjectionMatrix();
150}
151
153 mProjectionMatrix = glm::perspective(_fovy, _aspectRatio, _nearClipPlane, _farClipPlane);
154}
155
156#endif//CSCI441_PERSPECTIVE_CAMERA_HPP
Abstract Camera class to be placed (position and orientation) within our scene.
Abstract Class to represent a synthetic camera. The following methods must be overridden:
Definition: Camera.hpp:39
Abstract Class to represent a perspective camera. Stores aspect ratio and field of view.
Definition: PerspectiveCamera.hpp:22
PerspectiveCamera(const PerspectiveCamera &)=default
construct a copy an existing camera
void mUpdateProjectionMatrix()
computes the perspective projection matrix for the camera
Definition: PerspectiveCamera.hpp:152
PerspectiveCamera & operator=(const PerspectiveCamera &)=default
assign a copy of an existing camera
virtual void setNearClipPlane(GLfloat near) final
updates the camera's near clip plane
Definition: PerspectiveCamera.hpp:141
PerspectiveCamera(PerspectiveCamera &&)=default
construct a camera by moving ane existing camera object
virtual void setFarClipPlane(GLfloat far) final
updates the camera's far clip plane
Definition: PerspectiveCamera.hpp:147
virtual void setAspectRatio(GLfloat aspectRatio) final
updates the camera's aspect ratio
Definition: PerspectiveCamera.hpp:129
~PerspectiveCamera() override=default
properly destroy concrete children
PerspectiveCamera & operator=(PerspectiveCamera &&)=default
reassign an existing camera to ourselves
PerspectiveCamera(GLfloat aspectRatio=1.0f, GLfloat fovy=45.0f, GLfloat nearClipPlane=0.001f, GLfloat farClipPlane=1000.0f)
initializes the Perspective Camera
Definition: PerspectiveCamera.hpp:115
virtual void setVerticalFOV(GLfloat fovy) final
updates the camera's vertical field of view
Definition: PerspectiveCamera.hpp:135
CSCI441 Helper Functions for OpenGL.
Definition: ArcballCam.hpp:17