CSCI441 OpenGL Library 5.13.0
CS@Mines CSCI441 Computer Graphics Course Library
Loading...
Searching...
No Matches
FreeCam.hpp
Go to the documentation of this file.
1
12#ifndef CSCI441_FREE_CAM_HPP
13#define CSCI441_FREE_CAM_HPP
14
15#include "PerspectiveCamera.hpp"
16
17namespace CSCI441 {
18
23 class FreeCam final : public CSCI441::PerspectiveCamera {
24 public:
33 explicit FreeCam(GLfloat aspectRatio = 1.0f, GLfloat fovy = 45.0f, GLfloat nearClipPlane = 0.001f, GLfloat farClipPlane = 1000.0f);
34
38 FreeCam(const FreeCam&) = default;
43 FreeCam& operator=(const FreeCam&) = default;
44
48 FreeCam(FreeCam&&) = default;
53 FreeCam& operator=(FreeCam&&) = default;
54
58 ~FreeCam() override = default;
59
67 void recomputeOrientation() override;
68
74 void moveForward(GLfloat movementFactor) override;
75
81 void moveBackward(GLfloat movementFactor) override;
82
83 private:
84 // updates the look at point and recalculates the view matrix
85 void _updateFreeCameraViewMatrix();
86 };
87}
88
90 const GLfloat aspectRatio,
91 const GLfloat fovy,
92 const GLfloat nearClipPlane,
93 const GLfloat farClipPlane
94) : PerspectiveCamera(aspectRatio, fovy, nearClipPlane, farClipPlane)
95{
97}
98
100 // compute direction vector based on spherical to cartesian conversion
101 mCameraDirection.x = glm::sin(mCameraTheta ) * glm::sin(mCameraPhi );
102 mCameraDirection.y = -glm::cos(mCameraPhi );
103 mCameraDirection.z = -glm::cos(mCameraTheta ) * glm::sin(mCameraPhi );
104
105 // and normalize this directional vector!
106 mCameraDirection = glm::normalize(mCameraDirection );
107
108 _updateFreeCameraViewMatrix();
109}
110
111inline void CSCI441::FreeCam::moveForward(const GLfloat movementFactor) {
112 mCameraPosition += mCameraDirection * movementFactor;
113 _updateFreeCameraViewMatrix();
114}
115
116inline void CSCI441::FreeCam::moveBackward(const GLfloat movementFactor) {
117 mCameraPosition -= mCameraDirection * movementFactor;
118 _updateFreeCameraViewMatrix();
119}
120
121inline void CSCI441::FreeCam::_updateFreeCameraViewMatrix() {
122 setLookAtPoint(mCameraPosition + mCameraDirection );
123 computeViewMatrix();
124}
125
126#endif // CSCI441_FREE_CAM_HPP
A camera that implements a FreeCam camera model.
Definition: FreeCam.hpp:23
FreeCam(GLfloat aspectRatio=1.0f, GLfloat fovy=45.0f, GLfloat nearClipPlane=0.001f, GLfloat farClipPlane=1000.0f)
Definition: FreeCam.hpp:89
void recomputeOrientation() override
converts spherical theta & phi to cartesian x,y,z direction vector
Definition: FreeCam.hpp:99
~FreeCam() override=default
properly destroy concrete children
FreeCam(FreeCam &&)=default
construct a camera by moving ane existing camera object
FreeCam & operator=(const FreeCam &)=default
assign a copy of an existing camera
void moveBackward(GLfloat movementFactor) override
updates the camera's position by the adding the camera's negative direction to the camera's position
Definition: FreeCam.hpp:116
void moveForward(GLfloat movementFactor) override
updates the camera's position by the adding the camera's direction to the camera's position
Definition: FreeCam.hpp:111
FreeCam(const FreeCam &)=default
construct a copy an existing camera
FreeCam & operator=(FreeCam &&)=default
reassign an existing camera to ourselves
Abstract Class to represent a perspective camera. Stores aspect ratio and field of view.
Definition: PerspectiveCamera.hpp:11
CSCI441 Helper Functions for OpenGL.
Definition: ArcballCam.hpp:17