Answered step by step
Verified Expert Solution
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 D scene. Use the tap of a keyboard key to allow a user to change the view of the scene between orthographic D and perspective D 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 D 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 industrystandard 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 WINDOWWIDTH ;
const int WINDOWHEIGHT ;
const char gViewName "view";
const char gProjectionName "projection";
camera object used for viewing and interacting with
the 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;
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
mpShaderManager pShaderManager;
mpWindow NULL;
gpCamera new Camera;
default camera view parameters
gpCameraPosition glm::vecfff;
gpCameraFront glm::vecfff;
gpCameraUp glm::vecfff;
gpCameraZoom ;
gpCameraMovementSpeed ;
~ViewManager
ViewManager::~ViewManager
free up allocated memory
mpShaderManager NULL;
mpWindow NULL;
if NULL gpCamera
delete gpCamera;
gpCamera NULL;
CreateDisplayWindow
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;
tell GLFW to capture all mouse events
glfwSetInputModewindow GLFWCURSOR, GLFWCURSORDISABLED;
this callback is used to receive mouse moving events
glfwSetCursorPosCallbackwindow &ViewManager::MousePositionCallback;
enable blending for supporting transparent rendering
glEnableGLBLEND;
glBlendFuncGLSRCALPHA, GLONEMINUSSRCALPHA;
mpWindow window;
returnwindow;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored 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