CSCI441 OpenGL Library 5.13.0
CS@Mines CSCI441 Computer Graphics Course Library
Loading...
Searching...
No Matches
ArcballCam.hpp
Go to the documentation of this file.
1
12#ifndef CSCI441_ARCBALL_CAM_HPP
13#define CSCI441_ARCBALL_CAM_HPP
14
15#include "PerspectiveCamera.hpp"
16
17namespace CSCI441 {
18
24 public:
35 explicit ArcballCam(GLfloat minRadius = 2.0f, GLfloat maxRadius = 30.0f, GLfloat aspectRatio = 1.0f, GLfloat fovy = 45.0f, GLfloat nearClipPlane = 0.001f, GLfloat farClipPlane = 1000.0f);
36
40 ArcballCam(const ArcballCam&) = default;
45 ArcballCam& operator=(const ArcballCam&) = default;
46
50 ArcballCam(ArcballCam&&) = default;
56
60 ~ArcballCam() override = default;
61
68 void recomputeOrientation() override;
69
75 void moveForward(GLfloat movementFactor) override;
76
82 void moveBackward(GLfloat movementFactor) override;
83
84 private:
88 void _updateArcballCameraViewMatrix();
89
93 void _clampRadius();
94
98 GLfloat _minRadius;
102 GLfloat _maxRadius;
103 };
104}
105
107 const GLfloat minRadius,
108 const GLfloat maxRadius,
109 const GLfloat aspectRatio,
110 const GLfloat fovy,
111 const GLfloat nearClipPlane,
112 const GLfloat farClipPlane
113) : CSCI441::PerspectiveCamera(aspectRatio, fovy, nearClipPlane, farClipPlane),
114 _minRadius(minRadius),
115 _maxRadius(maxRadius)
116{
118}
119
121 // compute direction vector based on spherical to cartesian conversion
122 mCameraDirection.x = glm::sin(mCameraTheta ) * glm::sin(mCameraPhi ) * mCameraRadius;
123 mCameraDirection.y = -glm::cos(mCameraPhi ) * mCameraRadius;
124 mCameraDirection.z = -glm::cos(mCameraTheta ) * glm::sin(mCameraPhi ) * mCameraRadius;
125
126 _updateArcballCameraViewMatrix();
127}
128
129inline void CSCI441::ArcballCam::moveForward(const GLfloat movementFactor) {
130 mCameraRadius -= movementFactor; // camera "moves forward" by reducing the radius to get closer to the look at point
131 _clampRadius(); // ensure camera doesn't get too close
132 recomputeOrientation(); // update view matrix
133}
134
135inline void CSCI441::ArcballCam::moveBackward(const GLfloat movementFactor) {
136 mCameraRadius += movementFactor; // camera "moves backward" by increasing the radius to get further away from the look at point
137 _clampRadius(); // ensure camera doesn't get too far away
138 recomputeOrientation(); // update view matrix
139}
140
141inline void CSCI441::ArcballCam::_updateArcballCameraViewMatrix() {
142 setPosition(mCameraLookAtPoint + mCameraDirection );
143 computeViewMatrix();
144}
145
146inline void CSCI441::ArcballCam::_clampRadius() {
147 mCameraRadius = glm::clamp(mCameraRadius, _minRadius, _maxRadius);
148}
149
150#endif // CSCI441_ARCBALL_CAM_HPP
A camera that implements an ArcBall camera model.
Definition: ArcballCam.hpp:23
void recomputeOrientation() override
converts spherical theta & phi to cartesian x,y,z direction vector
Definition: ArcballCam.hpp:120
ArcballCam & operator=(const ArcballCam &)=default
assign a copy of an existing camera
~ArcballCam() override=default
properly destroy concrete children
ArcballCam & operator=(ArcballCam &&)=default
reassign an existing camera to ourselves
ArcballCam(const ArcballCam &)=default
construct a copy an existing camera
void moveForward(GLfloat movementFactor) override
updates the camera's position by decreasing the camera's radius
Definition: ArcballCam.hpp:129
void moveBackward(GLfloat movementFactor) override
updates the camera's position by increasing the camera's radius
Definition: ArcballCam.hpp:135
ArcballCam(ArcballCam &&)=default
construct a camera by moving ane existing camera object
ArcballCam(GLfloat minRadius=2.0f, GLfloat maxRadius=30.0f, GLfloat aspectRatio=1.0f, GLfloat fovy=45.0f, GLfloat nearClipPlane=0.001f, GLfloat farClipPlane=1000.0f)
initializes the Arcball Camera and sets the minimum/maximum radius the camera can zoom through as wel...
Definition: ArcballCam.hpp:106
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