Answered step by step
Verified Expert Solution
Link Copied!

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 3D 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 WINDOW_WIDTH =1000;
const int WINDOW_HEIGHT =800;
const char* g_ViewName = "view";
const char* g_ProjectionName = "projection";
// camera object used for viewing and interacting withthe 3D scene
Camera* g_pCamera = nullptr;
// these variables are used for mouse movement processing
float gLastX = WINDOW_WIDTH /2.0f;
float gLastY = WINDOW_HEIGHT /2.0f;
bool gFirstMouse = true;
// time between current frame and last frame
float gDeltaTime =0.0f;
float gLastFrame =0.0f;
// 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
m_pShaderManager = pShaderManager;
m_pWindow = NULL;
g_pCamera = new Camera();
// default camera view parameters
g_pCamera->Position = glm::vec3(0.5f,5.5f,10.0f);
g_pCamera->Front = glm::vec3(0.0f,-0.5f,-2.0f);
g_pCamera->Up = glm::vec3(0.0f,1.0f,0.0f);
g_pCamera->Zoom =80;
g_pCamera->MovementSpeed =10;}
* ~ViewManager()* The destructor for the class
ViewManager::~ViewManager(){
// free up allocated memory
m_pShaderManager = NULL;
m_pWindow = NULL;
if (NULL != g_pCamera){
delete g_pCamera;
g_pCamera = NULL;}}
* CreateDisplayWindow()* This method is used to create the main display window.
GLFWwindow* ViewManager::CreateDisplayWindow(const char* windowTitle){
GLFWwindow* window = nullptr;
// try to create the displayed OpenGL window
window = glfwCreateWindow(
WINDOW_WIDTH,
WINDOW_HEIGHT,
windowTitle,
NULL, NULL);
if (window == NULL){
std::cout << "Failed to create GLFW window" << std::endl;
glfwTerminate();
return NULL;}
glfwMakeContextCurrent(window);
// this callback is used to receive mouse moving events
glfwSetCursorPosCallback(window, &ViewManager::Mouse_Position_Callback);
// tell GLFW to capture all mouse events
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
// enable blending for supporting tranparent rendering
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
m_pWindow = window;
return(window);}
* Mouse_Position_Callback()* This method is automatically called from GLFW
void ViewManager::Mouse_Position_Callback(GLFWwindow* 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 3D camera accordingly
float xOffset = xMousePos - gLastX;
float yOffset = gLastY - yMousePos; // reversed since y-coordinates go from bottom to top
// set the current positions into the last position variables
gLastX = xMousePos;
gLastY = yMousePos;
// move the 3D camera according to the calculated offsets
g_pCamera->ProcessMouseMovement(xOffset, yOffset);}
* ProcessKeyboardEvents()* This method is called to
void ViewManager::ProcessKeyboardEvents({
// close the window if the escape key has been pressed
if (glfwGetKey(m_pWindow, GLFW_KEY_ESCAPE)== GLFW_PRESS){
glfwSetWindowShouldClose(m_pWindow, true);}
// if the camera object is null, then exit this method
if (NULL == g_pCamera){
return;}
// process camera zooming in and out
if (glfwGetKey(m_pWindow, GLFW_KEY_W)== GLFW_PRESS){
g_pC

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions