CSCI441 OpenGL Library 5.9.0
CS@Mines CSCI441 Computer Graphics Course Library
Loading...
Searching...
No Matches
Camera.hpp
Go to the documentation of this file.
1
15#ifndef CSCI441_CAMERA_HPP
16#define CSCI441_CAMERA_HPP
17
18#ifdef CSCI441_USE_GLEW
19 #include <GL/glew.h>
20#else
21 #include <glad/gl.h>
22#endif
23
24#include <glm/mat4x4.hpp>
25#include <glm/vec3.hpp>
26#include <glm/gtc/constants.hpp>
27#include <glm/gtc/matrix_transform.hpp>
28
29namespace CSCI441 {
30
37 class Camera {
38 public:
42 virtual ~Camera() = default;
43
51 virtual void recomputeOrientation() = 0;
52
57 [[maybe_unused]] virtual void moveForward(GLfloat movementFactor) = 0;
58
63 [[maybe_unused]] virtual void moveBackward(GLfloat movementFactor) = 0;
64
75 [[maybe_unused]] [[maybe_unused]] virtual void rotate(GLfloat dTheta, GLfloat dPhi);
76
81
86 [[maybe_unused]] [[nodiscard]] virtual glm::mat4 getProjectionMatrix() const final { return mProjectionMatrix; }
91 [[maybe_unused]] [[nodiscard]] virtual glm::mat4 getViewMatrix() const final { return mViewMatrix; }
96 [[nodiscard]] virtual glm::vec3 getPosition() const final { return mCameraPosition; }
101 [[nodiscard]] virtual glm::vec3 getLookAtPoint() const final { return mCameraLookAtPoint; }
106 [[nodiscard]] virtual glm::vec3 getUpVector() const final { return mCameraUpVector; }
111 [[nodiscard]] virtual GLfloat getTheta() const final { return mCameraTheta; }
116 [[nodiscard]] virtual GLfloat getPhi() const final { return mCameraPhi; }
121 [[maybe_unused]] [[nodiscard]] GLfloat getRadius() const { return mCameraRadius; }
122
127 virtual void setPosition( const glm::vec3 pos ) final { mCameraPosition = pos; }
132 virtual void setLookAtPoint( const glm::vec3 lookAt ) final { mCameraLookAtPoint = lookAt; }
137 virtual void setUpVector( const glm::vec3 up ) final { mCameraUpVector = up; }
142 virtual void setTheta( const GLfloat t ) final { mCameraTheta = t; }
147 virtual void setPhi( const GLfloat p ) final { mCameraPhi = p; }
152 virtual void setRadius( const GLfloat r ) final { mCameraRadius = r; }
153
154 protected:
159 Camera();
160
165
169 glm::mat4 mViewMatrix;
170
187
195 GLfloat mCameraPhi;
200
201 private:
206 void _clampCameraPhi();
207 };
208}
209
211 mProjectionMatrix( glm::mat4(1.0f) ),
212 mViewMatrix( glm::mat4(1.0f) ),
213 mCameraPosition( glm::vec3(0.0f, 0.0f, 0.0f ) ),
214 mCameraDirection( glm::vec3(0.0f, 0.0f, -1.0f ) ),
215 mCameraLookAtPoint( glm::vec3(0.0f, 0.0f, -1.0f ) ),
216 mCameraUpVector( glm::vec3(0.0f, 1.0f, 0.0f ) ),
217 mCameraTheta( 0.0f ),
218 mCameraPhi( glm::pi<float>() / 2.0f ),
219 mCameraRadius( 1.0f ) {
220}
221
222[[maybe_unused]]
223inline void CSCI441::Camera::rotate(const GLfloat dTheta, const GLfloat dPhi) {
224 mCameraTheta += dTheta; // update theta
225 mCameraPhi += dPhi; // update phi
226 _clampCameraPhi(); // bounds check phi
227 recomputeOrientation(); // convert to cartesian
228}
229
230inline void CSCI441::Camera::_clampCameraPhi() {
231 if(mCameraPhi <= 0.0f) mCameraPhi = 0.0f + 0.001f;
232 if(mCameraPhi >= glm::pi<float>()) mCameraPhi = glm::pi<float>() - 0.001f;
233}
234
235#endif // CSCI441_CAMERA_HPP
Abstract Class to represent a synthetic camera. The following methods must be overridden:
Definition: Camera.hpp:37
GLfloat mCameraPhi
spherical angle for pitch direction in radians
Definition: Camera.hpp:195
virtual void setRadius(const GLfloat r) final
sets the camera's radius in world space
Definition: Camera.hpp:152
virtual GLfloat getPhi() const final
returns the current phi value in radians
Definition: Camera.hpp:116
virtual void setTheta(const GLfloat t) final
sets the camera's theta angle in radians
Definition: Camera.hpp:142
Camera()
create a default camera at the origin, looking down the negative Z axis oriented with the world coord...
Definition: Camera.hpp:210
virtual glm::vec3 getLookAtPoint() const final
returns the current lookAt point in world space
Definition: Camera.hpp:101
virtual void moveBackward(GLfloat movementFactor)=0
steps backward along the camera's view
virtual void computeViewMatrix() final
creates the View Matrix based on the position, lookAt point, and up vector
Definition: Camera.hpp:80
virtual glm::mat4 getViewMatrix() const final
returns the current view matrix for the associated camera
Definition: Camera.hpp:91
virtual void recomputeOrientation()=0
Uses theta, phi, & radius to update the camera's view matrix parameters. The camera orientation is co...
virtual void setPosition(const glm::vec3 pos) final
sets the camera's position in world space
Definition: Camera.hpp:127
GLfloat mCameraTheta
spherical angle for yaw direction in radians
Definition: Camera.hpp:191
virtual GLfloat getTheta() const final
returns the current theta value in radians
Definition: Camera.hpp:111
virtual glm::vec3 getPosition() const final
returns the current camera position in world space
Definition: Camera.hpp:96
glm::mat4 mProjectionMatrix
stores the Projection Matrix
Definition: Camera.hpp:164
glm::vec3 mCameraPosition
the cartesian position in world space of the camera
Definition: Camera.hpp:174
virtual glm::vec3 getUpVector() const final
returns the current up vector in world space
Definition: Camera.hpp:106
virtual ~Camera()=default
properly destroy concrete children
glm::vec3 mCameraDirection
the cartesian direction the camera is facing in world space
Definition: Camera.hpp:178
glm::mat4 mViewMatrix
stores the View Matrix corresponding to the inverse of the Camera's Matrix
Definition: Camera.hpp:169
virtual void moveForward(GLfloat movementFactor)=0
steps forward along the camera's view
virtual void setLookAtPoint(const glm::vec3 lookAt) final
sets the camera's lookAt point in world space
Definition: Camera.hpp:132
glm::vec3 mCameraLookAtPoint
the world space point in front of the camera
Definition: Camera.hpp:182
virtual glm::mat4 getProjectionMatrix() const final
returns the current projection matrix for the associated camera
Definition: Camera.hpp:86
virtual void setPhi(const GLfloat p) final
sets the camera's phi angle in radians
Definition: Camera.hpp:147
virtual void setUpVector(const glm::vec3 up) final
sets the camera's up vector in world space
Definition: Camera.hpp:137
glm::vec3 mCameraUpVector
the up vector of the camera specified in world space
Definition: Camera.hpp:186
GLfloat mCameraRadius
spherical magnitude for direction in world space
Definition: Camera.hpp:199
virtual void rotate(GLfloat dTheta, GLfloat dPhi)
rotates the camera's POV by adding to theta & phi then ensuring phi stays within the (0,...
Definition: Camera.hpp:223
GLfloat getRadius() const
returns the current radius in world space
Definition: Camera.hpp:121
CSCI441 Helper Functions for OpenGL.
Definition: ArcballCam.hpp:17