Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create perspective and orthographic displays of a 3 D scene. Use the tap of a keyboard key to allow a user to change the view

Create perspective and orthographic displays of a 3D scene. Use the tap of a keyboard key to allow a user to change the view of the scene between orthographic (2D) and perspective (3D) views at will. Hint: Check the glViewport and the glOrtho functions. For consistency, use the letter P keyboard key for perspective view and the letter O key for orthographic view. To do this work, switch the function call to retrieve either the perspective or orthographic projection matrix. Because of the nature of the projection methods, the camera settings will be different between perspective and orthographic projection. For orthographic projection, the camera will look directly at the 3D object. The bottom plane should not be visible if the orthographic projection is correct.
Create code that follows a logical flow without syntax errors. The code you create has to be executable. The code that is included needs to be reached by the execution. You dont have to include everything in a single function. Your work should be well modularized.
Apply coding best practices in your creations. Pay particular attention to the way you format and comment your code. Program code should be easy to read and follow industry-standard code formatting practices, such as indentation and spacing. The source code should be brief and clear. Use descriptive comments.
#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 with
// the 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;
// the following variable is false when orthographic projection
// is off and true when it is on
bool bOrthographicProjection = false;}
* ViewManager()
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.0f,5.0f,12.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 =20;}
* ~ViewManager()
ViewManager::~ViewManager(){
// free up allocated memory
m_pShaderManager = NULL;
m_pWindow = NULL;
if (NULL != g_pCamera){
delete g_pCamera;
g_pCamera = NULL;}}
* CreateDisplayWindow()
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);
// tell GLFW to capture all mouse events
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
// this callback is used to receive mouse moving events
glfwSetCursorPosCallback(window, &ViewManager::Mouse_Position_Callback);
// enable blending for supporting transparent rendering
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
m_pWindow = window;
return(window);}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Pro SQL Server Wait Statistics

Authors: Enrico Van De Laar

1st Edition

1484211391, 9781484211397

More Books

Students also viewed these Databases questions