CSCI441 OpenGL Library 5.13.0
CS@Mines CSCI441 Computer Graphics Course Library
Loading...
Searching...
No Matches
PerspectiveCamera.hpp
1#ifndef CSCI441_PERSPECTIVE_CAMERA_HPP
2#define CSCI441_PERSPECTIVE_CAMERA_HPP
3
4#include "Camera.hpp"
5
6namespace CSCI441 {
7
12 public:
21 explicit PerspectiveCamera(GLfloat aspectRatio = 1.0f, GLfloat fovy = 45.0f, GLfloat nearClipPlane = 0.001f, GLfloat farClipPlane = 1000.0f);
22
26 ~PerspectiveCamera() override = default;
27
33 [[maybe_unused]] virtual void setAspectRatio(GLfloat aspectRatio) final;
34
40 [[maybe_unused]] virtual void setVerticalFOV(GLfloat fovy) final;
41
47 [[maybe_unused]] virtual void setNearClipPlane(GLfloat near) final;
48
54 [[maybe_unused]] virtual void setFarClipPlane(GLfloat far) final;
55
56 protected:
61
71
81
82 private:
87 GLfloat _fovy;
91 GLfloat _aspectRatio;
95 GLfloat _nearClipPlane;
99 GLfloat _farClipPlane;
100 };
101
102}
103
105 const GLfloat aspectRatio,
106 const GLfloat fovy,
107 const GLfloat nearClipPlane,
108 const GLfloat farClipPlane
109) : _fovy(fovy),
110 _aspectRatio(aspectRatio),
111 _nearClipPlane(nearClipPlane),
112 _farClipPlane(farClipPlane)
113{
115}
116
117[[maybe_unused]]
118inline void CSCI441::PerspectiveCamera::setAspectRatio(const GLfloat aspectRatio) {
119 _aspectRatio = aspectRatio;
120 mUpdateProjectionMatrix();
121}
122
123[[maybe_unused]]
124inline void CSCI441::PerspectiveCamera::setVerticalFOV(const GLfloat fovy) {
125 _fovy = fovy;
126 mUpdateProjectionMatrix();
127}
128
129[[maybe_unused]]
130inline void CSCI441::PerspectiveCamera::setNearClipPlane(const GLfloat near) {
131 _nearClipPlane = near;
132 mUpdateProjectionMatrix();
133}
134
135[[maybe_unused]]
136inline void CSCI441::PerspectiveCamera::setFarClipPlane(const GLfloat far) {
137 _farClipPlane = far;
138 mUpdateProjectionMatrix();
139}
140
142 mProjectionMatrix = glm::perspective(_fovy, _aspectRatio, _nearClipPlane, _farClipPlane);
143}
144
145#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:37
Abstract Class to represent a perspective camera. Stores aspect ratio and field of view.
Definition: PerspectiveCamera.hpp:11
PerspectiveCamera(const PerspectiveCamera &)=default
construct a copy an existing camera
void mUpdateProjectionMatrix()
computes the perspective projection matrix for the camera
Definition: PerspectiveCamera.hpp:141
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:130
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:136
virtual void setAspectRatio(GLfloat aspectRatio) final
updates the camera's aspect ratio
Definition: PerspectiveCamera.hpp:118
~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:104
virtual void setVerticalFOV(GLfloat fovy) final
updates the camera's vertical field of view
Definition: PerspectiveCamera.hpp:124
CSCI441 Helper Functions for OpenGL.
Definition: ArcballCam.hpp:17