CSCI441 OpenGL Library 6.0.2.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#include "constants.h"
19
20#ifdef CSCI441_USE_GLEW
21 #include <GL/glew.h>
22#else
23 #include <glad/gl.h>
24#endif
25
26#include <glm/mat4x4.hpp>
27#include <glm/vec3.hpp>
28#include <glm/gtc/constants.hpp>
29#include <glm/gtc/matrix_transform.hpp>
30
31namespace CSCI441 {
32
39 class Camera {
40 public:
44 virtual ~Camera() = default;
45
53 virtual void recomputeOrientation() = 0;
54
59 [[maybe_unused]] virtual void moveForward(GLfloat movementFactor) = 0;
60
65 [[maybe_unused]] virtual void moveBackward(GLfloat movementFactor) = 0;
66
77 [[maybe_unused]] [[maybe_unused]] virtual void rotate(GLfloat dTheta, GLfloat dPhi);
78
83
88 [[maybe_unused]] [[nodiscard]] virtual glm::mat4 getProjectionMatrix() const final { return mProjectionMatrix; }
93 [[maybe_unused]] [[nodiscard]] virtual glm::mat4 getViewMatrix() const final { return mViewMatrix; }
98 [[nodiscard]] virtual glm::vec3 getPosition() const final { return mCameraPosition; }
103 [[nodiscard]] virtual glm::vec3 getLookAtPoint() const final { return mCameraLookAtPoint; }
108 [[nodiscard]] virtual glm::vec3 getUpVector() const final { return glm::normalize(mCameraUpVector); }
113 [[nodiscard]] virtual GLfloat getTheta() const final { return mCameraTheta; }
118 [[nodiscard]] virtual GLfloat getPhi() const final { return mCameraPhi; }
123 [[maybe_unused]] [[nodiscard]] virtual GLfloat getRadius() const final { return mCameraRadius; }
128 [[maybe_unused]] [[nodiscard]] virtual glm::vec3 getViewDirection() const final { return glm::normalize(mCameraDirection); }
129
134 virtual void setPosition( const glm::vec3 pos ) final { mCameraPosition = pos; }
139 virtual void setLookAtPoint( const glm::vec3 lookAt ) final { mCameraLookAtPoint = lookAt; }
144 virtual void setUpVector( const glm::vec3 up ) final { mCameraUpVector = up; }
149 virtual void setTheta( const GLfloat t ) final { mCameraTheta = t; }
154 virtual void setPhi( const GLfloat p ) final { mCameraPhi = p; }
159 virtual void setRadius( const GLfloat r ) final { mCameraRadius = r; }
160
161 protected:
166 Camera();
167
171 Camera(const Camera&) = default;
176 Camera& operator=(const Camera&) = default;
177
181 Camera(Camera&&) = default;
186 Camera& operator=(Camera&&) = default;
187
192
196 glm::mat4 mViewMatrix;
197
214
222 GLfloat mCameraPhi;
227
228 private:
233 void _clampCameraPhi();
234 };
235}
236
238 mProjectionMatrix( glm::mat4(1.0f) ),
239 mViewMatrix( glm::mat4(1.0f) ),
240 mCameraPosition( glm::vec3(0.0f, 0.0f, 0.0f ) ),
241 mCameraDirection( glm::vec3(0.0f, 0.0f, -1.0f ) ),
242 mCameraLookAtPoint( glm::vec3(0.0f, 0.0f, -1.0f ) ),
243 mCameraUpVector( glm::vec3(0.0f, 1.0f, 0.0f ) ),
244 mCameraTheta( 0.0f ),
245 mCameraPhi( glm::pi<float>() / 2.0f ),
246 mCameraRadius( 1.0f ) {
247}
248
249[[maybe_unused]]
250inline void CSCI441::Camera::rotate(const GLfloat dTheta, const GLfloat dPhi) {
251 mCameraTheta += dTheta; // update theta
252 mCameraPhi += dPhi; // update phi
253 _clampCameraPhi(); // bounds check phi
254 recomputeOrientation(); // convert to cartesian
255}
256
257inline void CSCI441::Camera::_clampCameraPhi() {
258 if(mCameraPhi <= 0.0f) mCameraPhi = 0.0f + 0.001f;
259 if(mCameraPhi >= glm::pi<float>()) mCameraPhi = glm::pi<float>() - 0.001f;
260}
261
262#endif // CSCI441_CAMERA_HPP
Abstract Class to represent a synthetic camera. The following methods must be overridden:
Definition: Camera.hpp:39
virtual GLfloat getRadius() const final
returns the current radius in world space
Definition: Camera.hpp:123
GLfloat mCameraPhi
spherical angle for pitch direction in radians
Definition: Camera.hpp:222
virtual void setRadius(const GLfloat r) final
sets the camera's radius in world space
Definition: Camera.hpp:159
virtual GLfloat getPhi() const final
returns the current phi value in radians
Definition: Camera.hpp:118
virtual void setTheta(const GLfloat t) final
sets the camera's theta angle in radians
Definition: Camera.hpp:149
Camera()
create a default camera at the origin, looking down the negative Z axis oriented with the world coord...
Definition: Camera.hpp:237
virtual glm::vec3 getLookAtPoint() const final
returns the current lookAt point in world space
Definition: Camera.hpp:103
virtual void moveBackward(GLfloat movementFactor)=0
steps backward along the camera's view
Camera(Camera &&)=default
construct a camera by moving ane existing camera object
virtual void computeViewMatrix() final
creates the View Matrix based on the position, lookAt point, and up vector
Definition: Camera.hpp:82
virtual glm::mat4 getViewMatrix() const final
returns the current view matrix for the associated camera
Definition: Camera.hpp:93
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:134
GLfloat mCameraTheta
spherical angle for yaw direction in radians
Definition: Camera.hpp:218
virtual GLfloat getTheta() const final
returns the current theta value in radians
Definition: Camera.hpp:113
virtual glm::vec3 getPosition() const final
returns the current camera position in world space
Definition: Camera.hpp:98
glm::mat4 mProjectionMatrix
stores the Projection Matrix
Definition: Camera.hpp:191
glm::vec3 mCameraPosition
the cartesian position in world space of the camera
Definition: Camera.hpp:201
Camera & operator=(Camera &&)=default
reassign an existing camera to ourselves
virtual glm::vec3 getUpVector() const final
returns the current up vector in world space
Definition: Camera.hpp:108
virtual glm::vec3 getViewDirection() const final
returns the current direction the camera is facing
Definition: Camera.hpp:128
virtual ~Camera()=default
properly destroy concrete children
glm::vec3 mCameraDirection
the cartesian direction the camera is facing in world space
Definition: Camera.hpp:205
glm::mat4 mViewMatrix
stores the View Matrix corresponding to the inverse of the Camera's Matrix
Definition: Camera.hpp:196
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:139
glm::vec3 mCameraLookAtPoint
the world space point in front of the camera
Definition: Camera.hpp:209
Camera & operator=(const Camera &)=default
assign a copy of an existing camera
Camera(const Camera &)=default
construct a copy an existing camera
virtual glm::mat4 getProjectionMatrix() const final
returns the current projection matrix for the associated camera
Definition: Camera.hpp:88
virtual void setPhi(const GLfloat p) final
sets the camera's phi angle in radians
Definition: Camera.hpp:154
virtual void setUpVector(const glm::vec3 up) final
sets the camera's up vector in world space
Definition: Camera.hpp:144
glm::vec3 mCameraUpVector
the up vector of the camera specified in world space
Definition: Camera.hpp:213
GLfloat mCameraRadius
spherical magnitude for direction in world space
Definition: Camera.hpp:226
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:250
CSCI441 Helper Functions for OpenGL.
Definition: ArcballCam.hpp:17