CSCI441 OpenGL Library 5.9.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
42 void recomputeOrientation() final;
43
49 void moveForward(GLfloat movementFactor) final;
50
56 void moveBackward(GLfloat movementFactor) final;
57
58 private:
59 // updates the look at point and recalculates the view matrix
60 void _updateFreeCameraViewMatrix();
61 };
62}
63
65 const GLfloat aspectRatio,
66 const GLfloat fovy,
67 const GLfloat nearClipPlane,
68 const GLfloat farClipPlane
69) : PerspectiveCamera(aspectRatio, fovy, nearClipPlane, farClipPlane)
70{
72}
73
75 // compute direction vector based on spherical to cartesian conversion
76 mCameraDirection.x = glm::sin(mCameraTheta ) * glm::sin(mCameraPhi );
77 mCameraDirection.y = -glm::cos(mCameraPhi );
78 mCameraDirection.z = -glm::cos(mCameraTheta ) * glm::sin(mCameraPhi );
79
80 // and normalize this directional vector!
81 mCameraDirection = glm::normalize(mCameraDirection );
82
83 _updateFreeCameraViewMatrix();
84}
85
86inline void CSCI441::FreeCam::moveForward(const GLfloat movementFactor) {
87 mCameraPosition += mCameraDirection * movementFactor;
88 _updateFreeCameraViewMatrix();
89}
90
91inline void CSCI441::FreeCam::moveBackward(const GLfloat movementFactor) {
92 mCameraPosition -= mCameraDirection * movementFactor;
93 _updateFreeCameraViewMatrix();
94}
95
96inline void CSCI441::FreeCam::_updateFreeCameraViewMatrix() {
97 setLookAtPoint(mCameraPosition + mCameraDirection );
98 computeViewMatrix();
99}
100
101#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:64
void moveForward(GLfloat movementFactor) final
updates the camera's position by the adding the camera's direction to the camera's position
Definition: FreeCam.hpp:86
void moveBackward(GLfloat movementFactor) final
updates the camera's position by the adding the camera's negative direction to the camera's position
Definition: FreeCam.hpp:91
void recomputeOrientation() final
converts spherical theta & phi to cartesian x,y,z direction vector
Definition: FreeCam.hpp:74
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