CSCI441 OpenGL Library 5.9.0
CS@Mines CSCI441 Computer Graphics Course Library
Loading...
Searching...
No Matches
OpenGL3DEngine.hpp
Go to the documentation of this file.
1
12#ifndef CSCI441_OPENGL3D_ENGINE_HPP
13#define CSCI441_OPENGL3D_ENGINE_HPP
14
15#include "ArcballCam.hpp"
16#include "OpenGLEngine.hpp"
17
18#include <glm/glm.hpp>
19#include <glm/gtc/constants.hpp>
20
21namespace CSCI441 {
22
34 public:
43
48 [[maybe_unused]] [[nodiscard]] virtual GLboolean isLeftMouseDown() const noexcept final { return mIsLeftMouseDown; }
53 [[maybe_unused]] virtual void setLeftMouseDown(GLboolean isDown) final { mIsLeftMouseDown = isDown; }
54
59 [[maybe_unused]] [[nodiscard]] virtual GLboolean isShiftDown() const noexcept final { return mIsShiftDown; }
64 [[maybe_unused]] virtual void setShiftDown(GLboolean isDown) final { mIsShiftDown = isDown; }
65
70 [[maybe_unused]] [[nodiscard]] virtual glm::vec2 getMousePosition() const noexcept final { return mMousePosition; }
75 [[maybe_unused]] virtual void setMousePosition(glm::vec2 mousePos) final { mMousePosition = mousePos; }
76
81 [[maybe_unused]] virtual void setArcballCameraAngles( glm::vec3 angles ) final {
82 mpArcballCamera->setTheta(angles[0] );
83 mpArcballCamera->setPhi(angles[1] );
84 mpArcballCamera->setRadius(angles[2] );
85 }
86
91 [[maybe_unused]] [[nodiscard]] virtual glm::vec3 getArcballCameraEyePoint() const noexcept final { return mpArcballCamera->getPosition(); }
92
97 [[maybe_unused]] [[nodiscard]] virtual glm::vec3 getArcballCameraLookAtPoint() const noexcept final { return mpArcballCamera->getLookAtPoint(); }
102 [[maybe_unused]] virtual void setArcballCameraLookAtPoint( glm::vec3 lookAtPoint ) final { mpArcballCamera->setLookAtPoint(lookAtPoint); }
103
108 [[maybe_unused]] [[nodiscard]] virtual glm::vec3 getArcballCameraUpVector() const noexcept final { return mpArcballCamera->getUpVector(); }
113 [[maybe_unused]] virtual void setArcballCameraUpVector( glm::vec3 upVector ) final { mpArcballCamera->setUpVector(upVector); }
114
119 [[maybe_unused]] [[nodiscard]] virtual glm::mat4 getArcballProjectionMatrix() const final { return mpArcballCamera->getProjectionMatrix(); }
120
125 [[maybe_unused]] [[nodiscard]] virtual glm::mat4 getArcballViewMatrix() const final { return mpArcballCamera->getViewMatrix(); }
126
131 [[maybe_unused]] virtual void addToArcballCameraAngles( glm::vec3 angleAdditions ) final {
132 mpArcballCamera->setTheta(mpArcballCamera->getTheta() + angleAdditions[0] );
133 mpArcballCamera->setPhi(mpArcballCamera->getPhi() + angleAdditions[1] );
134 mpArcballCamera->moveBackward(angleAdditions[2] );
135 }
136
140 [[maybe_unused]] virtual void updateArcballCameraDirection() final {
142 }
143
149 [[maybe_unused]] virtual void handleCameraCursorPosEvent(double x, double y) final {
150 glm::vec2 currMousePos(x, getWindowHeight() - y);
151
152 if( mIsLeftMouseDown ) {
153 if( !mIsShiftDown ) {
154 // rotate the camera by the distance the mouse moved
155 mpArcballCamera->rotate((currMousePos.x - mMousePosition.x) * 0.005f,
156 (mMousePosition.y - currMousePos.y) * 0.005f);
157 } else {
158 // otherwise, update our camera angles theta & phi
159 GLfloat totChgSq = (currMousePos.x - mMousePosition.x) + (currMousePos.y - mMousePosition.y);
160 mpArcballCamera->moveForward( totChgSq * 0.05f );
161 }
162 }
163
164 setMousePosition(currMousePos);
165 }
166
174 [[maybe_unused]] virtual void handleCameraKeyEvent(int key, int scancode, int action, int mods) final {
175 if( key == GLFW_KEY_LEFT_SHIFT ) {
176 _isLeftShiftDown = (action == GLFW_PRESS || action == GLFW_REPEAT);
177 } else if( key == GLFW_KEY_RIGHT_SHIFT ) {
178 _isRightShiftDown = (action == GLFW_PRESS || action == GLFW_REPEAT);
179 }
180 mIsShiftDown = _isLeftShiftDown || _isRightShiftDown;
181 }
182
189 [[maybe_unused]] virtual void handleCameraMouseButtonEvent(int button, int action, int mods) final {
190 if( button == GLFW_MOUSE_BUTTON_LEFT ) {
191 mIsLeftMouseDown = (action == GLFW_PRESS);
192 }
193 }
194
200 [[maybe_unused]] virtual void handleCameraScrollEvent(double xOffset, double yOffset) {
201 mpArcballCamera->moveForward((GLfloat)yOffset * 0.2f );
202 }
203
209 [[maybe_unused]] void handleCameraAspectRatioEvent(int width, int height) {
210 mpArcballCamera->setAspectRatio( (GLfloat)width / (GLfloat)height );
211 }
212
213 protected:
226 OpenGL3DEngine(int OPENGL_MAJOR_VERSION, int OPENGL_MINOR_VERSION, int WINDOW_WIDTH, int WINDOW_HEIGHT, const char* WINDOW_TITLE, bool WINDOW_RESIZABLE = GLFW_FALSE);
230 ~OpenGL3DEngine() override;
231
236
240 GLboolean mIsShiftDown;
248 glm::vec2 mMousePosition;
249
250 private:
254 GLboolean _isLeftShiftDown;
258 GLboolean _isRightShiftDown;
259 };
260}
261
262//*****************************************************************************************
263
264inline CSCI441::OpenGL3DEngine::OpenGL3DEngine(const int OPENGL_MAJOR_VERSION, const int OPENGL_MINOR_VERSION, const int WINDOW_WIDTH, const int WINDOW_HEIGHT, const char* WINDOW_TITLE, const bool WINDOW_RESIZABLE)
265 : OpenGLEngine(OPENGL_MAJOR_VERSION, OPENGL_MINOR_VERSION, WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_TITLE, WINDOW_RESIZABLE),
266 mpArcballCamera( new CSCI441::ArcballCam(2.0f, 30.0f, (GLfloat)WINDOW_WIDTH / (GLfloat)WINDOW_HEIGHT) ),
267 mIsShiftDown( GL_FALSE ),
268 mIsLeftMouseDown( GL_FALSE ),
269 mMousePosition( glm::vec2(0.0f, 0.0f) ),
270 _isLeftShiftDown(GL_FALSE),
271 _isRightShiftDown(GL_FALSE) {
272
273}
274
276 delete mpArcballCamera;
277}
278
279#endif // CSCI441_OPENGL3D_ENGINE_HPP
Concrete Arcball Camera implementation with Perspective Projection.
Abstract class engine class to setup window, register callbacks, vaos, textures, and shaders,...
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
virtual void setRadius(const GLfloat r) final
sets the camera's radius in world space
Definition: Camera.hpp:152
virtual GLfloat getPhi() const final
returns the current phi value in radians
Definition: Camera.hpp:116
virtual void setTheta(const GLfloat t) final
sets the camera's theta angle in radians
Definition: Camera.hpp:142
virtual glm::vec3 getLookAtPoint() const final
returns the current lookAt point in world space
Definition: Camera.hpp:101
virtual glm::mat4 getViewMatrix() const final
returns the current view matrix for the associated camera
Definition: Camera.hpp:91
virtual GLfloat getTheta() const final
returns the current theta value in radians
Definition: Camera.hpp:111
virtual glm::vec3 getPosition() const final
returns the current camera position in world space
Definition: Camera.hpp:96
virtual glm::vec3 getUpVector() const final
returns the current up vector in world space
Definition: Camera.hpp:106
virtual void setLookAtPoint(const glm::vec3 lookAt) final
sets the camera's lookAt point in world space
Definition: Camera.hpp:132
virtual glm::mat4 getProjectionMatrix() const final
returns the current projection matrix for the associated camera
Definition: Camera.hpp:86
virtual void setPhi(const GLfloat p) final
sets the camera's phi angle in radians
Definition: Camera.hpp:147
virtual void setUpVector(const glm::vec3 up) final
sets the camera's up vector in world space
Definition: Camera.hpp:137
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:223
Abstract Class to run an OpenGL application with a 3D environment. Creates and contains a default ...
Definition: OpenGL3DEngine.hpp:33
virtual void setLeftMouseDown(GLboolean isDown) final
set the status of the left mouse button being down
Definition: OpenGL3DEngine.hpp:53
virtual void handleCameraScrollEvent(double xOffset, double yOffset)
zooms camera inward/outward based on scroll direction
Definition: OpenGL3DEngine.hpp:200
glm::vec2 mMousePosition
current mouse position in screen space
Definition: OpenGL3DEngine.hpp:248
GLboolean mIsShiftDown
if either shift key (left or right) is currently pressed
Definition: OpenGL3DEngine.hpp:240
virtual void handleCameraCursorPosEvent(double x, double y) final
moves camera for active cursor movement
Definition: OpenGL3DEngine.hpp:149
virtual glm::mat4 getArcballProjectionMatrix() const final
returns the current projection matrix for the arcball camera
Definition: OpenGL3DEngine.hpp:119
virtual void handleCameraKeyEvent(int key, int scancode, int action, int mods) final
tracks if either shift key is currently being pressed
Definition: OpenGL3DEngine.hpp:174
virtual glm::vec3 getArcballCameraEyePoint() const noexcept final
the world space position the arcball camera is located at
Definition: OpenGL3DEngine.hpp:91
virtual void setShiftDown(GLboolean isDown) final
set the status of the shift keys being down
Definition: OpenGL3DEngine.hpp:64
GLboolean mIsLeftMouseDown
if the mouse left button is currently pressed
Definition: OpenGL3DEngine.hpp:244
virtual GLboolean isShiftDown() const noexcept final
the status of either shift key being down
Definition: OpenGL3DEngine.hpp:59
virtual void handleCameraMouseButtonEvent(int button, int action, int mods) final
tracks left mouse button state
Definition: OpenGL3DEngine.hpp:189
void handleCameraAspectRatioEvent(int width, int height)
resizes camera aspect ratio
Definition: OpenGL3DEngine.hpp:209
CSCI441::ArcballCam * mpArcballCamera
pointer to the ArcballCam object
Definition: OpenGL3DEngine.hpp:235
OpenGL3DEngine & operator=(const OpenGL3DEngine &)=delete
do not allow engines to be copied
virtual void setMousePosition(glm::vec2 mousePos) final
set the location of the mouse within the window
Definition: OpenGL3DEngine.hpp:75
virtual GLboolean isLeftMouseDown() const noexcept final
the status of the left mouse button being down
Definition: OpenGL3DEngine.hpp:48
~OpenGL3DEngine() override
cleans up OpenGL 3D Engine by deleting arcball camera object
Definition: OpenGL3DEngine.hpp:275
OpenGL3DEngine(const OpenGL3DEngine &)=delete
do not allow engines to be copied
virtual void addToArcballCameraAngles(glm::vec3 angleAdditions) final
moves the arcball spherical object space coordinate by the associated amounts
Definition: OpenGL3DEngine.hpp:131
virtual glm::vec2 getMousePosition() const noexcept final
the location of the mouse within the window
Definition: OpenGL3DEngine.hpp:70
virtual void setArcballCameraLookAtPoint(glm::vec3 lookAtPoint) final
set the world space position the arcball camera is looking at and thus centered around
Definition: OpenGL3DEngine.hpp:102
virtual void updateArcballCameraDirection() final
recomputes the arcball camera's world space position
Definition: OpenGL3DEngine.hpp:140
virtual glm::mat4 getArcballViewMatrix() const final
returns the current view matrix for the arcball camera
Definition: OpenGL3DEngine.hpp:125
virtual glm::vec3 getArcballCameraLookAtPoint() const noexcept final
the world space position the arcball camera is looking at and thus centered around
Definition: OpenGL3DEngine.hpp:97
virtual void setArcballCameraUpVector(glm::vec3 upVector) final
sets the world space vector the arcball camera is oriented upwards along
Definition: OpenGL3DEngine.hpp:113
virtual glm::vec3 getArcballCameraUpVector() const noexcept final
the world space vector the arcball camera is oriented upwards along
Definition: OpenGL3DEngine.hpp:108
virtual void setArcballCameraAngles(glm::vec3 angles) final
sets the object space position of the arcball camera in spherical world coordinates
Definition: OpenGL3DEngine.hpp:81
Abstract Class to run an OpenGL application. The following methods must be overridden:
Definition: OpenGLEngine.hpp:39
virtual int getWindowHeight() const noexcept final
Return the height of the window.
Definition: OpenGLEngine.hpp:105
virtual void setAspectRatio(GLfloat aspectRatio) final
updates the camera's aspect ratio
Definition: PerspectiveCamera.hpp:93
CSCI441 Helper Functions for OpenGL.
Definition: ArcballCam.hpp:17