CSCI441 OpenGL Library 5.9.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
43 void recomputeOrientation() final;
44
50 void moveForward(GLfloat movementFactor) final;
51
57 void moveBackward(GLfloat movementFactor) final;
58
59 private:
63 void _updateArcballCameraViewMatrix();
64
68 void _clampRadius();
69
73 GLfloat _minRadius;
77 GLfloat _maxRadius;
78 };
79}
80
82 const GLfloat minRadius,
83 const GLfloat maxRadius,
84 const GLfloat aspectRatio,
85 const GLfloat fovy,
86 const GLfloat nearClipPlane,
87 const GLfloat farClipPlane
88) : CSCI441::PerspectiveCamera(aspectRatio, fovy, nearClipPlane, farClipPlane),
89 _minRadius(minRadius),
90 _maxRadius(maxRadius)
91{
93}
94
96 // compute direction vector based on spherical to cartesian conversion
97 mCameraDirection.x = glm::sin(mCameraTheta ) * glm::sin(mCameraPhi ) * mCameraRadius;
98 mCameraDirection.y = -glm::cos(mCameraPhi ) * mCameraRadius;
99 mCameraDirection.z = -glm::cos(mCameraTheta ) * glm::sin(mCameraPhi ) * mCameraRadius;
100
101 _updateArcballCameraViewMatrix();
102}
103
104inline void CSCI441::ArcballCam::moveForward(const GLfloat movementFactor) {
105 mCameraRadius -= movementFactor; // camera "moves forward" by reducing the radius to get closer to the look at point
106 _clampRadius(); // ensure camera doesn't get too close
107 recomputeOrientation(); // update view matrix
108}
109
110inline void CSCI441::ArcballCam::moveBackward(const GLfloat movementFactor) {
111 mCameraRadius += movementFactor; // camera "moves backward" by increasing the radius to get further away from the look at point
112 _clampRadius(); // ensure camera doesn't get too far away
113 recomputeOrientation(); // update view matrix
114}
115
116inline void CSCI441::ArcballCam::_updateArcballCameraViewMatrix() {
117 setPosition(mCameraLookAtPoint + mCameraDirection );
118 computeViewMatrix();
119}
120
121inline void CSCI441::ArcballCam::_clampRadius() {
122 mCameraRadius = glm::clamp(mCameraRadius, _minRadius, _maxRadius);
123}
124
125#endif // CSCI441_ARCBALL_CAM_HPP
A camera that implements an ArcBall camera model.
Definition: ArcballCam.hpp:23
void recomputeOrientation() final
converts spherical theta & phi to cartesian x,y,z direction vector
Definition: ArcballCam.hpp:95
void moveForward(GLfloat movementFactor) final
updates the camera's position by decreasing the camera's radius
Definition: ArcballCam.hpp:104
void moveBackward(GLfloat movementFactor) final
updates the camera's position by increasing the camera's radius
Definition: ArcballCam.hpp:110
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:81
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