Answered step by step
Verified Expert Solution
Question
00
1 Approved Answer
Colorful objects on a scale. The goal of this assignment is to add commented modern OpenGL code for panning, zooming, and orbiting a 3 D
Colorful objects on a scale. The goal of this assignment is to add commented modern OpenGL code for panning, zooming, and orbiting a D scene. Use the keyboard, mouse, and movement combinations below: WASD keys to control the forward zoom in backward zoom out left, and pan right motion. QE keys to control the upward and downward movement. Mouse cursor to change the orientation of the camera to look up and down or right and left. Mouse scroll to adjust the speed of the movement or the speed the camera travels around the scene. Specifically address the following rubric criteria: Create code to address the required functionality. Apply logic and proper syntax to code. Source code should be free of logical or syntax errors that prevent the application from running. Apply commenting and formatting standards to facilitate understanding of the code. All code should be well commented. comments should be as clear and brief as possible. comments should explain the purpose of lines or sections of the code. document any sections of code that produce errors or incorrect results. Organize all code to meet formatting standards. #include "ViewManager.h GLM Math Header inclusions #include #include #include declaration of the global variables and defines namespace Variables for window width and height const int WINDOWWIDTH ; const int WINDOWHEIGHT ; const char gViewName "view"; const char gProjectionName "projection"; camera object used for viewing and interacting withthe D scene Camera gpCamera nullptr; these variables are used for mouse movement processing float gLastX WINDOWWIDTH f; float gLastY WINDOWHEIGHT f; bool gFirstMouse true; time between current frame and last frame float gDeltaTime f; float gLastFrame f; if orthographic projection is on this value will be true bool bOrthographicProjection false; ViewManager The constructor for the class ViewManager::ViewManager ShaderManager pShaderManager initialize the member variables mpShaderManager pShaderManager; mpWindow NULL; gpCamera new Camera; default camera view parameters gpCameraPosition glm::vecfff; gpCameraFront glm::vecfff; gpCameraUp glm::vecfff; gpCameraZoom ; gpCameraMovementSpeed ; ~ViewManager The destructor for the class ViewManager::~ViewManager free up allocated memory mpShaderManager NULL; mpWindow NULL; if NULL gpCamera delete gpCamera; gpCamera NULL; CreateDisplayWindow This method is used to create the main display window. GLFWwindow ViewManager::CreateDisplayWindowconst char windowTitle GLFWwindow window nullptr; try to create the displayed OpenGL window window glfwCreateWindow WINDOWWIDTH, WINDOWHEIGHT, windowTitle, NULL, NULL; if window NULL std::cout "Failed to create GLFW window" std::endl; glfwTerminate; return NULL; glfwMakeContextCurrentwindow; this callback is used to receive mouse moving events glfwSetCursorPosCallbackwindow &ViewManager::MousePositionCallback; tell GLFW to capture all mouse events glfwSetInputModewindow GLFWCURSOR, GLFWCURSORDISABLED; enable blending for supporting tranparent rendering glEnableGLBLEND; glBlendFuncGLSRCALPHA, GLONEMINUSSRCALPHA; mpWindow window; returnwindow; MousePositionCallback This method is automatically called from GLFW void ViewManager::MousePositionCallbackGLFWwindow window, double xMousePos, double yMousePos when the first mouse move event is received, this needs to be recorded so that all subsequent mouse moves can correctly calculate the X position offset and Y position offset for proper operation if gFirstMouse gLastX xMousePos; gLastY yMousePos; gFirstMouse false; calculate the X offset and Y offset values for moving the D camera accordingly float xOffset xMousePos gLastX; float yOffset gLastY yMousePos; reversed since ycoordinates go from bottom to top set the current positions into the last position variables gLastX xMousePos; gLastY yMousePos; move the D camera according to the calculated offsets gpCameraProcessMouseMovementxOffset yOffset; ProcessKeyboardEvents This method is called to void ViewManager::ProcessKeyboardEvents close the window if the escape key has been pressed if glfwGetKeympWindow, GLFWKEYESCAPE GLFWPRESS glfwSetWindowShouldClosempWindow, true; if the camera object is null, then exit this method if NULL gpCamera return; process camera zooming in and out if glfwGetKeympWindow, GLFWKEYW GLFWPRESS gpC
Colorful objects on a scale. The goal of this assignment is to add commented modern OpenGL code for panning, zooming, and orbiting a D scene. Use the keyboard, mouse, and movement combinations below: WASD keys to control the forward zoom in backward zoom out left, and pan right motion. QE keys to control the upward and downward movement. Mouse cursor to change the orientation of the camera to look up and down or right and left. Mouse scroll to adjust the speed of the movement or the speed the camera travels around the scene. Specifically address the following rubric criteria: Create code to address the required functionality. Apply logic and proper syntax to code. Source code should be free of logical or syntax errors that prevent the application from running. Apply commenting and formatting standards to facilitate understanding of the code. All code should be well commented. comments should be as clear and brief as possible. comments should explain the purpose of lines or sections of the code. document any sections of code that produce errors or incorrect results. Organize all code to meet formatting standards.
#include "ViewManager.h
GLM Math Header inclusions
#include
#include
#include
declaration of the global variables and defines
namespace
Variables for window width and height
const int WINDOWWIDTH ;
const int WINDOWHEIGHT ;
const char gViewName "view";
const char gProjectionName "projection";
camera object used for viewing and interacting withthe D scene
Camera gpCamera nullptr;
these variables are used for mouse movement processing
float gLastX WINDOWWIDTH f;
float gLastY WINDOWHEIGHT f;
bool gFirstMouse true;
time between current frame and last frame
float gDeltaTime f;
float gLastFrame f;
if orthographic projection is on this value will be true
bool bOrthographicProjection false;
ViewManager The constructor for the class
ViewManager::ViewManager
ShaderManager pShaderManager
initialize the member variables
mpShaderManager pShaderManager;
mpWindow NULL;
gpCamera new Camera;
default camera view parameters
gpCameraPosition glm::vecfff;
gpCameraFront glm::vecfff;
gpCameraUp glm::vecfff;
gpCameraZoom ;
gpCameraMovementSpeed ;
~ViewManager The destructor for the class
ViewManager::~ViewManager
free up allocated memory
mpShaderManager NULL;
mpWindow NULL;
if NULL gpCamera
delete gpCamera;
gpCamera NULL;
CreateDisplayWindow This method is used to create the main display window.
GLFWwindow ViewManager::CreateDisplayWindowconst char windowTitle
GLFWwindow window nullptr;
try to create the displayed OpenGL window
window glfwCreateWindow
WINDOWWIDTH,
WINDOWHEIGHT,
windowTitle,
NULL, NULL;
if window NULL
std::cout "Failed to create GLFW window" std::endl;
glfwTerminate;
return NULL;
glfwMakeContextCurrentwindow;
this callback is used to receive mouse moving events
glfwSetCursorPosCallbackwindow &ViewManager::MousePositionCallback;
tell GLFW to capture all mouse events
glfwSetInputModewindow GLFWCURSOR, GLFWCURSORDISABLED;
enable blending for supporting tranparent rendering
glEnableGLBLEND;
glBlendFuncGLSRCALPHA, GLONEMINUSSRCALPHA;
mpWindow window;
returnwindow;
MousePositionCallback This method is automatically called from GLFW
void ViewManager::MousePositionCallbackGLFWwindow window, double xMousePos, double yMousePos
when the first mouse move event is received, this needs to be recorded so that
all subsequent mouse moves can correctly calculate the X position offset and Y
position offset for proper operation
if gFirstMouse
gLastX xMousePos;
gLastY yMousePos;
gFirstMouse false;
calculate the X offset and Y offset values for moving the D camera accordingly
float xOffset xMousePos gLastX;
float yOffset gLastY yMousePos; reversed since ycoordinates go from bottom to top
set the current positions into the last position variables
gLastX xMousePos;
gLastY yMousePos;
move the D camera according to the calculated offsets
gpCameraProcessMouseMovementxOffset yOffset;
ProcessKeyboardEvents This method is called to
void ViewManager::ProcessKeyboardEvents
close the window if the escape key has been pressed
if glfwGetKeympWindow, GLFWKEYESCAPE GLFWPRESS
glfwSetWindowShouldClosempWindow, true;
if the camera object is null, then exit this method
if NULL gpCamera
return;
process camera zooming in and out
if glfwGetKeympWindow, GLFWKEYW GLFWPRESS
gpC
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started