2020-02-20 22:18:07 -08:00
|
|
|
/*
|
2020-02-21 03:45:32 -08:00
|
|
|
Title : Execution
|
|
|
|
Author: Edward R. Gonzalez
|
2020-02-13 22:13:16 -08:00
|
|
|
|
2020-02-21 03:45:32 -08:00
|
|
|
Description:
|
|
|
|
This brings together the functionality I made in DGL and the Actions libraries to produce an OpenGL Workspace.
|
2020-02-20 22:18:07 -08:00
|
|
|
|
2020-02-21 03:45:32 -08:00
|
|
|
Currently the workspace is heavily hardcoded and has one light rotating around the specified object. The material for the object is set during prep as well.
|
2020-02-20 22:18:07 -08:00
|
|
|
|
2020-02-21 03:45:32 -08:00
|
|
|
All exposed library references are inside the inline namespace right after declaring the namespace execution.
|
|
|
|
|
|
|
|
After I have the global objects used, followed by the functionality implementations, and at the very end the main function running the default execution implementation.
|
2020-02-20 22:18:07 -08:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// DGL
|
2020-02-21 03:45:32 -08:00
|
|
|
#include "DGL/DGL.hpp"
|
2020-02-20 22:18:07 -08:00
|
|
|
|
|
|
|
// Utility
|
2020-02-15 19:32:26 -08:00
|
|
|
#include "Actions.hpp"
|
2020-02-13 22:13:16 -08:00
|
|
|
|
2020-02-20 22:18:07 -08:00
|
|
|
// Non-Standard C++
|
2020-02-13 22:13:16 -08:00
|
|
|
#include "Cpp_Alias.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Execution
|
|
|
|
{
|
2020-02-20 22:18:07 -08:00
|
|
|
inline namespace LibraryReferences
|
2020-02-13 22:13:16 -08:00
|
|
|
{
|
2020-02-15 19:32:26 -08:00
|
|
|
// DGL
|
|
|
|
|
2020-02-20 22:18:07 -08:00
|
|
|
using DGL::EBool ;
|
|
|
|
using DGL::ECursorMode ;
|
2020-02-15 19:32:26 -08:00
|
|
|
using DGL::EDirection ;
|
|
|
|
using DGL::EFrameBuffer ;
|
|
|
|
using DGL::EKeyCodes ;
|
2020-02-20 22:18:07 -08:00
|
|
|
using DGL::EMouseMode ;
|
2020-02-15 19:32:26 -08:00
|
|
|
using DGL::EPrimitives ;
|
|
|
|
using DGL::ERotationAxis;
|
|
|
|
|
2020-02-20 22:18:07 -08:00
|
|
|
using DGL::Camera ;
|
|
|
|
using DGL::Entity_Basic ;
|
|
|
|
using DGL::gFloat ;
|
|
|
|
using DGL::Light_Basic ;
|
|
|
|
using DGL::LinearColor ;
|
|
|
|
using DGL::Material_Phong;
|
|
|
|
using DGL::Matrix ;
|
|
|
|
using DGL::Matrix4x4 ;
|
|
|
|
using DGL::Model ;
|
|
|
|
using DGL::TimeValDec ;
|
|
|
|
using DGL::Vector3 ;
|
|
|
|
using DGL::Window ;
|
2020-02-15 19:32:26 -08:00
|
|
|
|
2020-02-20 22:18:07 -08:00
|
|
|
using DGL::BindVertexArray ;
|
2020-02-15 19:32:26 -08:00
|
|
|
using DGL::CanUseRawMouse ;
|
|
|
|
using DGL::ClearBuffer ;
|
|
|
|
using DGL::CreateWindow ;
|
2020-02-20 22:18:07 -08:00
|
|
|
using DGL::DestoryWindow ;
|
2020-02-15 19:32:26 -08:00
|
|
|
using DGL::DisableVertexAttributeArray;
|
2020-02-20 22:18:07 -08:00
|
|
|
using DGL::EnableDepth ;
|
2020-02-15 19:32:26 -08:00
|
|
|
using DGL::EnableVertexAttributeArray ;
|
|
|
|
using DGL::GetCursorPosition ;
|
|
|
|
using DGL::GetTime ;
|
|
|
|
using DGL::InitalizeGLEW ;
|
|
|
|
using DGL::InitalizeGLFW ;
|
2020-02-16 22:28:24 -08:00
|
|
|
using DGL::LoadDefaultShaders ;
|
2020-02-15 19:32:26 -08:00
|
|
|
using DGL::KeyPressed ;
|
|
|
|
using DGL::NotShared ;
|
|
|
|
using DGL::PollEvents ;
|
|
|
|
using DGL::ResetCursor ;
|
|
|
|
using DGL::SetClearColor ;
|
|
|
|
using DGL::SetCurrentContext ;
|
|
|
|
using DGL::SetInputMode ;
|
|
|
|
using DGL::SetPolygonMode ;
|
|
|
|
using DGL::SetUniformVariable_MVA ;
|
|
|
|
using DGL::SwapBuffers ;
|
|
|
|
using DGL::UseProgramShader ;
|
|
|
|
using DGL::TerminateGLFW ;
|
|
|
|
using DGL::WindowedMode ;
|
|
|
|
|
|
|
|
using DGL::DefaultSpace::ScreenWidth ;
|
|
|
|
using DGL::DefaultSpace::ScreenHeight ;
|
|
|
|
using DGL::DefaultSpace::ScreenCenterHeight;
|
|
|
|
using DGL::DefaultSpace::ScreenCenterWidth ;
|
|
|
|
using DGL::DefaultSpace::Screenspace ;
|
|
|
|
using DGL::DefaultSpace::WorldCamera ;
|
|
|
|
|
|
|
|
using DGL::DefaultSpace::UpdateScreenspace;
|
|
|
|
|
|
|
|
// Actions
|
|
|
|
|
|
|
|
using Actions::ActionQueue;
|
2020-02-13 22:13:16 -08:00
|
|
|
}
|
|
|
|
|
2020-02-21 03:45:32 -08:00
|
|
|
enum class EModels
|
|
|
|
{
|
|
|
|
Bunny ,
|
|
|
|
Cube ,
|
|
|
|
Eight ,
|
|
|
|
Gargoyle ,
|
|
|
|
Hand ,
|
|
|
|
Sculpture,
|
|
|
|
Topology ,
|
|
|
|
Torus
|
|
|
|
};
|
|
|
|
|
2020-02-13 22:13:16 -08:00
|
|
|
|
2020-02-15 19:32:26 -08:00
|
|
|
// Globals
|
2020-02-13 22:13:16 -08:00
|
|
|
|
2020-02-15 19:32:26 -08:00
|
|
|
bool Exist = true; // Determines if the the execution should exit cycler.
|
2020-02-13 22:13:16 -08:00
|
|
|
|
2020-02-21 03:45:32 -08:00
|
|
|
TimeValDec CycleStart , // Snapshot of cycle loop start time.
|
|
|
|
CycleEnd , // Snapshot of cycle loop end time.
|
|
|
|
DeltaTime , // Delta between last cycle start and end.
|
|
|
|
InputInterval = 1.0f / 144.0f, // Interval per second to complete the input process of the cycle.
|
|
|
|
PhysicsInterval = 1.0f / 144.0f, // Interval per second to complete the physics process of the cycle.
|
2020-02-17 00:38:40 -08:00
|
|
|
RenderInterval = 1.0f / 144.0f ; // Interval per second to complete the render process of the cycle.
|
2020-02-13 22:13:16 -08:00
|
|
|
|
2020-02-15 19:32:26 -08:00
|
|
|
ptr<Window> DefaultWindow; // Default window to use for execution.
|
2020-02-13 22:13:16 -08:00
|
|
|
|
2020-02-15 19:32:26 -08:00
|
|
|
double CursorX, CursorY; // Cursor axis position on the window.
|
2020-02-13 22:13:16 -08:00
|
|
|
|
2020-02-21 03:45:32 -08:00
|
|
|
bool CursorOff = true, ShowLight = true;
|
2020-02-17 18:10:15 -08:00
|
|
|
|
2020-02-21 03:45:32 -08:00
|
|
|
gFloat CamMoveSpeed = 7.0f, // Rate at which the camera should move.
|
2020-02-17 00:38:40 -08:00
|
|
|
CamRotationSpeed = 27.0f ; // Rate at which the camera should rotate.
|
2020-02-13 22:13:16 -08:00
|
|
|
|
2020-02-15 19:32:26 -08:00
|
|
|
TimeValDec InputDelta = 0.0, // Current delta since last input process.
|
|
|
|
PhysicsDelta = 0.0, // Current delta since last physics process.
|
|
|
|
RenderDelta = 0.0 ; // Current delta since last render process.
|
2020-02-13 22:13:16 -08:00
|
|
|
|
2020-02-15 19:32:26 -08:00
|
|
|
ActionQueue ActionsToComplete; // Actions queue to run during the physics process of the cycle.
|
2020-02-14 23:21:27 -08:00
|
|
|
|
2020-02-21 03:45:32 -08:00
|
|
|
EModels CurrentModel = EModels::Torus;
|
|
|
|
|
|
|
|
Model Bunny ("./Models/bunny.obj" );
|
|
|
|
Model Cube ("./Models/blenderCube2.obj");
|
|
|
|
Model Eight ("./Models/eight.obj" );
|
|
|
|
Model Gargoyle ("./Models/gargoyle.obj" );
|
|
|
|
Model Hand ("./Models/hand.obj" );
|
|
|
|
Model Horse ("./Models/horse.obj" );
|
|
|
|
Model Sculpture("./Models/sculpture.obj" );
|
|
|
|
Model Topology ("./Models/topology.obj" );
|
|
|
|
Model Torus ("./Models/Torus.obj" );
|
2020-02-20 22:18:07 -08:00
|
|
|
|
|
|
|
Material_Phong ObjectMaterial;
|
|
|
|
|
|
|
|
Light_Basic Light ; // Hardcoded light. Rotates around object.
|
|
|
|
Entity_Basic ObjectToView; // Object that will be currently in the middle with the light source rotating.
|
|
|
|
|
|
|
|
|
2020-02-21 03:45:32 -08:00
|
|
|
string
|
|
|
|
windowTitle = "Assignment 1" ,
|
|
|
|
deltaStr = "Delta: " ,
|
|
|
|
inputDeltaStr = "Input Delta: " ,
|
|
|
|
physicsDeltaStr = "Physics Delta: " ,
|
|
|
|
renderDeltaStr = "RenderDeltaStr: " ;
|
|
|
|
|
|
|
|
stringstream WindowTitle;
|
|
|
|
|
|
|
|
|
2020-02-14 23:21:27 -08:00
|
|
|
|
|
|
|
|
2020-02-15 19:32:26 -08:00
|
|
|
// Functionality
|
2020-02-14 23:21:27 -08:00
|
|
|
|
2020-02-21 03:45:32 -08:00
|
|
|
sfn ChangeModel()
|
|
|
|
{
|
|
|
|
if (CurrentModel == EModels::Torus)
|
|
|
|
{
|
|
|
|
CurrentModel = EModels::Bunny;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CurrentModel = EModels(int(CurrentModel) + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (CurrentModel)
|
|
|
|
{
|
|
|
|
case EModels::Bunny:
|
|
|
|
{
|
|
|
|
if (not Bunny.Ready())
|
|
|
|
{
|
|
|
|
glfwSetWindowTitle(DefaultWindow, "Assignment 1: Loading Bunny...");
|
|
|
|
|
|
|
|
Bunny.Load();
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjectToView.SetModel(Bunny);
|
|
|
|
|
|
|
|
ObjectToView.SetScale(4.0f);
|
|
|
|
|
|
|
|
ObjectToView.SetPosition(Vector3(-0.05, -4.4f, 0));
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case EModels::Cube:
|
|
|
|
{
|
|
|
|
if (not Cube.Ready())
|
|
|
|
{
|
|
|
|
glfwSetWindowTitle(DefaultWindow, "Assignment 1: Loading Cube...");
|
|
|
|
|
|
|
|
Cube.Load();
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjectToView.SetModel(Cube);
|
|
|
|
|
|
|
|
ObjectToView.SetScale(1.0f);
|
|
|
|
|
|
|
|
ObjectToView.SetPosition(Vector3(0, -1.0, 0));
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case EModels::Eight:
|
|
|
|
{
|
|
|
|
if (not Eight.Ready())
|
|
|
|
{
|
|
|
|
glfwSetWindowTitle(DefaultWindow, "Assignment 1: Loading Eight...");
|
|
|
|
|
|
|
|
Eight.Load();
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjectToView.SetModel(Eight);
|
|
|
|
|
|
|
|
//ObjectToView.Scale(1.0f);
|
|
|
|
|
|
|
|
ObjectToView.SetPosition(Vector3(0, -1.0, 0));
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case EModels::Gargoyle:
|
|
|
|
{
|
|
|
|
if (not Gargoyle.Ready())
|
|
|
|
{
|
|
|
|
glfwSetWindowTitle(DefaultWindow, "Assignment 1: Loading Gargoyle...");
|
|
|
|
|
|
|
|
Gargoyle.Load();
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjectToView.SetModel(Gargoyle);
|
|
|
|
|
|
|
|
ObjectToView.SetPosition(Vector3(-1, -5.4f, 0));
|
|
|
|
|
|
|
|
ObjectToView.SetScale(6.0f);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case EModels::Hand:
|
|
|
|
{
|
|
|
|
if (not Hand.Ready())
|
|
|
|
{
|
|
|
|
glfwSetWindowTitle(DefaultWindow, "Assignment 1: Loading Hand...");
|
|
|
|
|
|
|
|
Hand.Load();
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjectToView.SetModel(Hand);
|
|
|
|
|
|
|
|
ObjectToView.SetScale(0.03f);
|
|
|
|
|
|
|
|
ObjectToView.SetPosition(Vector3(0, -1.1f, 0));
|
|
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case EModels::Sculpture:
|
|
|
|
{
|
|
|
|
if (not Sculpture.Ready())
|
|
|
|
{
|
|
|
|
glfwSetWindowTitle(DefaultWindow, "Assignment 1: Loading Sculpture...");
|
|
|
|
|
|
|
|
Sculpture.Load();
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjectToView.SetModel(Sculpture);
|
|
|
|
|
|
|
|
ObjectToView.SetScale(0.01f);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case EModels::Topology:
|
|
|
|
{
|
|
|
|
if (not Topology.Ready())
|
|
|
|
{
|
|
|
|
glfwSetWindowTitle(DefaultWindow, "Assignment 1: Loading Topology...");
|
|
|
|
|
|
|
|
Topology.Load();
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjectToView.SetModel(Topology);
|
|
|
|
|
|
|
|
ObjectToView.SetScale(0.2f);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case EModels::Torus:
|
|
|
|
{
|
|
|
|
if (not Torus.Ready())
|
|
|
|
{
|
|
|
|
glfwSetWindowTitle(DefaultWindow, "Assignment 1: Loading Torus...");
|
|
|
|
|
|
|
|
Torus.Load();
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjectToView.SetModel(Torus);
|
|
|
|
|
|
|
|
ObjectToView.SetScale(1.0f);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
deduce ChangeModelDelegate = Delegate<decltype(ChangeModel)>(ChangeModel);
|
|
|
|
|
2020-02-20 22:18:07 -08:00
|
|
|
|
2020-02-21 03:45:32 -08:00
|
|
|
sfn ToggleLight()
|
|
|
|
{
|
|
|
|
if (ShowLight)
|
|
|
|
{
|
|
|
|
ShowLight = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ShowLight = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
deduce ToogleLightDelegate = Delegate<decltype(ToggleLight)>(ToggleLight);
|
2020-02-20 22:18:07 -08:00
|
|
|
|
|
|
|
// Input Action common functions...
|
2020-02-14 23:21:27 -08:00
|
|
|
|
2020-02-20 22:18:07 -08:00
|
|
|
sfn RotateCamera(ERotationAxis _rotationAxis, gFloat _rotationAmount, double _delta)
|
2020-02-14 23:21:27 -08:00
|
|
|
{
|
2020-02-20 22:18:07 -08:00
|
|
|
WorldCamera.Rotate(_rotationAxis, _rotationAmount, gFloat(_delta));
|
2020-02-15 19:32:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
deduce RotateCamDelegate = Delegate<decltype(RotateCamera)>(RotateCamera);
|
2020-02-14 23:21:27 -08:00
|
|
|
|
2020-02-20 22:18:07 -08:00
|
|
|
|
|
|
|
sfn MoveCamera(EDirection _direction, gFloat _translationAmount, double _delta)
|
2020-02-14 23:21:27 -08:00
|
|
|
{
|
2020-02-20 22:18:07 -08:00
|
|
|
WorldCamera.Move(_direction, _translationAmount, gFloat(_delta));
|
2020-02-15 19:32:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
deduce MoveCamDelegate = Delegate<decltype(MoveCamera)>(MoveCamera);
|
2020-02-14 23:21:27 -08:00
|
|
|
|
2020-02-20 22:18:07 -08:00
|
|
|
|
|
|
|
// This is here cause its super repetitive..
|
|
|
|
sfn ModifyCamSpeed(bool _isPositive, double _delta)
|
|
|
|
{
|
|
|
|
if (_isPositive)
|
|
|
|
{
|
|
|
|
CamMoveSpeed += CamMoveSpeed * gFloat(_delta);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CamMoveSpeed -= CamMoveSpeed * gFloat(_delta);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
deduce ModifyCamSpeedDelegate = Delegate<decltype(ModifyCamSpeed)>(ModifyCamSpeed);
|
|
|
|
deduce SetPolyModeDelegate = Delegate<decltype(SetPolygonMode)>(SetPolygonMode);
|
|
|
|
|
|
|
|
|
|
|
|
// End of common input functions...
|
|
|
|
|
2020-02-21 03:45:32 -08:00
|
|
|
sfn UpdateWindowDeltaTitle()
|
|
|
|
{
|
|
|
|
WindowTitle.str("");
|
|
|
|
|
|
|
|
WindowTitle
|
|
|
|
<< windowTitle << " "
|
|
|
|
<< deltaStr << DeltaTime << " "
|
|
|
|
<< inputDeltaStr << InputDelta << " "
|
|
|
|
<< physicsDeltaStr << PhysicsDelta << " "
|
|
|
|
<< renderDeltaStr << RenderDelta ;
|
|
|
|
}
|
|
|
|
|
2020-02-14 23:21:27 -08:00
|
|
|
|
|
|
|
|
2020-02-15 19:32:26 -08:00
|
|
|
// Currently Does everything required before entering the cycler.
|
|
|
|
sfn PrepWorkspace()
|
2020-02-14 23:21:27 -08:00
|
|
|
{
|
2020-02-20 22:18:07 -08:00
|
|
|
// Baseline
|
|
|
|
|
2020-02-15 19:32:26 -08:00
|
|
|
InitalizeGLFW();
|
2020-02-13 22:13:16 -08:00
|
|
|
|
2020-02-20 22:18:07 -08:00
|
|
|
DefaultWindow = CreateWindow(ScreenWidth, ScreenHeight, "Assignment 1: Loading Model...", WindowedMode(), NotShared());
|
2020-02-13 22:13:16 -08:00
|
|
|
|
2020-02-15 19:32:26 -08:00
|
|
|
SetCurrentContext(DefaultWindow);
|
2020-02-13 22:13:16 -08:00
|
|
|
|
2020-02-15 19:32:26 -08:00
|
|
|
InitalizeGLEW(); // Glew must initialize only after a context is set.
|
2020-02-13 22:13:16 -08:00
|
|
|
|
2020-02-20 22:18:07 -08:00
|
|
|
EnableDepth();
|
|
|
|
|
|
|
|
SetPolygonMode(DGL::EFace::Front_and_Back, DGL::ERenderMode::Fill);
|
|
|
|
|
2020-02-15 19:32:26 -08:00
|
|
|
// Cursor stuff
|
2020-02-13 22:13:16 -08:00
|
|
|
|
2020-02-15 19:32:26 -08:00
|
|
|
SetInputMode(DefaultWindow, DGL::EMouseMode::Cursor, DGL::ECursorMode::Disable);
|
2020-02-13 22:13:16 -08:00
|
|
|
|
2020-02-15 19:32:26 -08:00
|
|
|
ResetCursor(DefaultWindow, ScreenCenterWidth, ScreenCenterHeight);
|
2020-02-13 22:13:16 -08:00
|
|
|
|
2020-02-15 19:32:26 -08:00
|
|
|
if (CanUseRawMouse())
|
|
|
|
{
|
|
|
|
SetInputMode(DefaultWindow, DGL::EMouseMode::RawMouse, DGL::EBool::True);
|
|
|
|
}
|
2020-02-13 22:13:16 -08:00
|
|
|
|
2020-02-15 19:32:26 -08:00
|
|
|
// End of cursor stuff...
|
2020-02-13 22:13:16 -08:00
|
|
|
|
2020-02-20 22:18:07 -08:00
|
|
|
// Shaders
|
2020-02-13 22:13:16 -08:00
|
|
|
|
2020-02-20 22:18:07 -08:00
|
|
|
LoadDefaultShaders();
|
2020-02-16 22:28:24 -08:00
|
|
|
|
2020-02-20 22:18:07 -08:00
|
|
|
// Entities
|
2020-02-16 22:28:24 -08:00
|
|
|
|
2020-02-20 22:18:07 -08:00
|
|
|
Light.Load();
|
2020-02-16 22:28:24 -08:00
|
|
|
|
2020-02-21 03:45:32 -08:00
|
|
|
Torus.Load();
|
2020-02-16 22:28:24 -08:00
|
|
|
|
2020-02-21 03:45:32 -08:00
|
|
|
ObjectMaterial.Color = DGL::Colors::WarmSphia.Vector();
|
|
|
|
ObjectMaterial.Ambience = 0.112f ;
|
|
|
|
ObjectMaterial.Diffuse = 0.928f ;
|
|
|
|
ObjectMaterial.Specular = 0.21f ;
|
2020-02-16 22:28:24 -08:00
|
|
|
|
2020-02-21 03:45:32 -08:00
|
|
|
ObjectToView = Entity_Basic(Torus, ObjectMaterial);
|
2020-02-16 22:28:24 -08:00
|
|
|
}
|
2020-02-14 23:21:27 -08:00
|
|
|
|
|
|
|
|
2020-02-15 19:32:26 -08:00
|
|
|
/*
|
|
|
|
Cycles the process of what to do while a window is open.
|
2020-02-14 23:21:27 -08:00
|
|
|
|
2020-02-15 19:32:26 -08:00
|
|
|
The input, physics, and render procedures can be specified with extra functionality by specifying delegates to those procedures.
|
2020-02-14 23:21:27 -08:00
|
|
|
|
2020-02-15 19:32:26 -08:00
|
|
|
Cycler is hardcoded to exit if escape key is pressed.
|
|
|
|
*/
|
2020-02-20 22:18:07 -08:00
|
|
|
sfn Cycler(ro Ref(Delegate< Func<void, ptr<Window>> >) _inputProcedure, ro Ref(Delegate< Func<void>>) _physicsProcedure, ro Ref(Delegate< Func<void>>) _renderProcedure)
|
2020-02-13 22:13:16 -08:00
|
|
|
{
|
|
|
|
while (Exist)
|
|
|
|
{
|
2020-02-15 19:32:26 -08:00
|
|
|
CycleStart = GetTime();
|
2020-02-13 22:13:16 -08:00
|
|
|
|
2020-02-15 19:32:26 -08:00
|
|
|
if (InputDelta >= InputInterval)
|
2020-02-13 22:13:16 -08:00
|
|
|
{
|
2020-02-15 19:32:26 -08:00
|
|
|
PollEvents();
|
2020-02-14 23:21:27 -08:00
|
|
|
|
2020-02-15 19:32:26 -08:00
|
|
|
if (KeyPressed(DefaultWindow, EKeyCodes::Escape))
|
|
|
|
{
|
|
|
|
Exist = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
GetCursorPosition(DefaultWindow, Address(CursorX), Address(CursorY));
|
2020-02-14 23:21:27 -08:00
|
|
|
|
|
|
|
_inputProcedure(DefaultWindow);
|
|
|
|
|
2020-02-17 18:10:15 -08:00
|
|
|
if (CursorOff)
|
|
|
|
{
|
|
|
|
ResetCursor(DefaultWindow, ScreenCenterWidth, ScreenCenterHeight);
|
|
|
|
}
|
2020-02-13 22:13:16 -08:00
|
|
|
}
|
|
|
|
|
2020-02-14 23:21:27 -08:00
|
|
|
if (PhysicsDelta >= PhysicsInterval)
|
2020-02-13 22:13:16 -08:00
|
|
|
{
|
2020-02-15 19:32:26 -08:00
|
|
|
while (ActionsToComplete.HasAction())
|
|
|
|
{
|
|
|
|
ActionsToComplete.DoNextAction();
|
|
|
|
}
|
2020-02-14 23:21:27 -08:00
|
|
|
|
2020-02-15 19:32:26 -08:00
|
|
|
_physicsProcedure();
|
2020-02-14 23:21:27 -08:00
|
|
|
|
|
|
|
PhysicsDelta = 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (RenderDelta >= RenderInterval)
|
|
|
|
{
|
2020-02-15 19:32:26 -08:00
|
|
|
ClearBuffer(EFrameBuffer::Color, EFrameBuffer::Depth);
|
2020-02-14 23:21:27 -08:00
|
|
|
|
2020-02-21 03:45:32 -08:00
|
|
|
SetClearColor(LinearColor(0.02f, 0.02f, 0.02f, 1.0f));
|
2020-02-14 23:21:27 -08:00
|
|
|
|
2020-02-13 22:13:16 -08:00
|
|
|
_renderProcedure();
|
2020-02-14 23:21:27 -08:00
|
|
|
|
2020-02-15 19:32:26 -08:00
|
|
|
SwapBuffers(DefaultWindow);
|
2020-02-14 23:21:27 -08:00
|
|
|
|
|
|
|
RenderDelta = 0.0;
|
2020-02-13 22:13:16 -08:00
|
|
|
}
|
|
|
|
|
2020-02-20 22:18:07 -08:00
|
|
|
if (InputDelta >= InputInterval)
|
|
|
|
{
|
|
|
|
InputDelta = 0.0;
|
|
|
|
}
|
|
|
|
|
2020-02-15 19:32:26 -08:00
|
|
|
CycleEnd = GetTime();
|
2020-02-14 23:21:27 -08:00
|
|
|
|
|
|
|
DeltaTime = CycleEnd - CycleStart;
|
2020-02-13 22:13:16 -08:00
|
|
|
|
2020-02-14 23:21:27 -08:00
|
|
|
InputDelta += DeltaTime;
|
|
|
|
PhysicsDelta += DeltaTime;
|
|
|
|
RenderDelta += DeltaTime;
|
2020-02-13 22:13:16 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-14 23:21:27 -08:00
|
|
|
sfn InputProcedure(ptr<Window> _currentWindowContext)
|
2020-02-13 22:13:16 -08:00
|
|
|
{
|
2020-02-20 22:18:07 -08:00
|
|
|
if (KeyPressed(_currentWindowContext, EKeyCodes::F1))
|
2020-02-14 23:21:27 -08:00
|
|
|
{
|
|
|
|
ECursorMode cursorMode = ECursorMode(GetMouseInputMode(DefaultWindow, EMouseMode::Cursor));
|
|
|
|
|
2020-02-17 00:38:40 -08:00
|
|
|
deduce delegate = Delegate<decltype(SetInputMode<ECursorMode>)>(SetInputMode<ECursorMode>);
|
|
|
|
deduce delegateRaw = Delegate<decltype(SetInputMode<EBool >)>(SetInputMode<EBool >);
|
2020-02-15 19:32:26 -08:00
|
|
|
|
2020-02-14 23:21:27 -08:00
|
|
|
if (cursorMode == ECursorMode::Normal || cursorMode == ECursorMode::Hidden)
|
|
|
|
{
|
2020-02-17 00:38:40 -08:00
|
|
|
ActionsToComplete.AddToQueue(delegate , _currentWindowContext, EMouseMode::Cursor , ECursorMode::Disable);
|
|
|
|
ActionsToComplete.AddToQueue(delegateRaw, _currentWindowContext, EMouseMode::RawMouse, EBool ::True );
|
2020-02-17 18:10:15 -08:00
|
|
|
|
|
|
|
CursorOff = true;
|
2020-02-14 23:21:27 -08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-02-17 00:38:40 -08:00
|
|
|
ActionsToComplete.AddToQueue(delegate , _currentWindowContext, EMouseMode::Cursor , ECursorMode::Normal);
|
|
|
|
ActionsToComplete.AddToQueue(delegateRaw, _currentWindowContext, EMouseMode::RawMouse, EBool ::False );
|
2020-02-17 18:10:15 -08:00
|
|
|
|
|
|
|
CursorOff = false;
|
2020-02-14 23:21:27 -08:00
|
|
|
}
|
|
|
|
}
|
2020-02-13 22:13:16 -08:00
|
|
|
|
2020-02-21 03:45:32 -08:00
|
|
|
if (KeyPressed(_currentWindowContext, EKeyCodes::H))
|
|
|
|
{
|
|
|
|
ActionsToComplete.AddToQueue(ToogleLightDelegate);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (KeyPressed(_currentWindowContext, EKeyCodes::M))
|
|
|
|
{
|
|
|
|
ActionsToComplete.AddToQueue(ChangeModelDelegate);
|
|
|
|
}
|
|
|
|
|
2020-02-16 22:28:24 -08:00
|
|
|
if (KeyPressed(_currentWindowContext, EKeyCodes::UpArrow))
|
|
|
|
{
|
2020-02-17 09:39:31 -08:00
|
|
|
ActionsToComplete.AddToQueue(ModifyCamSpeedDelegate, true, PhysicsDelta);
|
2020-02-16 22:28:24 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (KeysPressed(_currentWindowContext, EKeyCodes::DnArrow))
|
|
|
|
{
|
2020-02-17 09:39:31 -08:00
|
|
|
ActionsToComplete.AddToQueue(ModifyCamSpeedDelegate, false, PhysicsDelta);
|
2020-02-16 22:28:24 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (KeyPressed(_currentWindowContext, EKeyCodes::F2))
|
|
|
|
{
|
|
|
|
ActionsToComplete.AddToQueue(SetPolyModeDelegate, DGL::EFace::Front_and_Back, DGL::ERenderMode::Line);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (KeyPressed(_currentWindowContext, EKeyCodes::F3))
|
|
|
|
{
|
|
|
|
ActionsToComplete.AddToQueue(SetPolyModeDelegate, DGL::EFace::Front_and_Back, DGL::ERenderMode::Fill);
|
|
|
|
}
|
|
|
|
|
2020-02-17 18:10:15 -08:00
|
|
|
if (CursorOff)
|
2020-02-14 23:21:27 -08:00
|
|
|
{
|
2020-02-17 18:10:15 -08:00
|
|
|
if (CursorX != 0)
|
|
|
|
{
|
2020-02-20 22:18:07 -08:00
|
|
|
ActionsToComplete.AddToQueue(RotateCamDelegate, ERotationAxis::Yaw, gFloat(CursorX) * CamRotationSpeed, PhysicsDelta);
|
2020-02-17 18:10:15 -08:00
|
|
|
}
|
2020-02-14 23:21:27 -08:00
|
|
|
|
2020-02-17 18:10:15 -08:00
|
|
|
if (CursorY != 0)
|
|
|
|
{
|
2020-02-20 22:18:07 -08:00
|
|
|
ActionsToComplete.AddToQueue(RotateCamDelegate, ERotationAxis::Pitch, gFloat(CursorY) * CamRotationSpeed, PhysicsDelta);
|
2020-02-17 18:10:15 -08:00
|
|
|
}
|
2020-02-14 23:21:27 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (KeyPressed(_currentWindowContext, EKeyCodes::E))
|
|
|
|
{
|
2020-02-15 19:32:26 -08:00
|
|
|
ActionsToComplete.AddToQueue(MoveCamDelegate, EDirection::Up, CamMoveSpeed, PhysicsDelta);
|
2020-02-14 23:21:27 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (KeyPressed(_currentWindowContext, EKeyCodes::Q))
|
|
|
|
{
|
2020-02-15 19:32:26 -08:00
|
|
|
ActionsToComplete.AddToQueue(MoveCamDelegate, EDirection::Down, CamMoveSpeed, PhysicsDelta);
|
2020-02-14 23:21:27 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (KeyPressed(_currentWindowContext, EKeyCodes::A))
|
|
|
|
{
|
2020-02-15 19:32:26 -08:00
|
|
|
ActionsToComplete.AddToQueue(MoveCamDelegate, EDirection::Left, CamMoveSpeed, PhysicsDelta);
|
2020-02-14 23:21:27 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (KeyPressed(_currentWindowContext, EKeyCodes::D))
|
|
|
|
{
|
2020-02-15 19:32:26 -08:00
|
|
|
ActionsToComplete.AddToQueue(MoveCamDelegate, EDirection::Right, CamMoveSpeed, PhysicsDelta);
|
2020-02-14 23:21:27 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (KeyPressed(_currentWindowContext, EKeyCodes::W))
|
|
|
|
{
|
2020-02-15 19:32:26 -08:00
|
|
|
ActionsToComplete.AddToQueue(MoveCamDelegate, EDirection::Forward, CamMoveSpeed, PhysicsDelta);
|
2020-02-14 23:21:27 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (KeyPressed(_currentWindowContext, EKeyCodes::S))
|
|
|
|
{
|
2020-02-15 19:32:26 -08:00
|
|
|
ActionsToComplete.AddToQueue(MoveCamDelegate, EDirection::Backward, CamMoveSpeed, PhysicsDelta);
|
2020-02-14 23:21:27 -08:00
|
|
|
}
|
2020-02-17 18:10:15 -08:00
|
|
|
|
|
|
|
if (KeyPressed(_currentWindowContext, EKeyCodes::I))
|
|
|
|
{
|
|
|
|
ActionsToComplete.AddToQueue(RotateCamDelegate, ERotationAxis::Pitch, -6.0f * CamRotationSpeed, PhysicsDelta);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (KeyPressed(_currentWindowContext, EKeyCodes::K))
|
|
|
|
{
|
|
|
|
ActionsToComplete.AddToQueue(RotateCamDelegate, ERotationAxis::Pitch, 6.0f * CamRotationSpeed, PhysicsDelta);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (KeyPressed(_currentWindowContext, EKeyCodes::J))
|
|
|
|
{
|
|
|
|
ActionsToComplete.AddToQueue(RotateCamDelegate, ERotationAxis::Yaw, -6.0f * CamRotationSpeed, PhysicsDelta);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (KeyPressed(_currentWindowContext, EKeyCodes::L))
|
|
|
|
{
|
|
|
|
ActionsToComplete.AddToQueue(RotateCamDelegate, ERotationAxis::Yaw, 6.0f * CamRotationSpeed, PhysicsDelta);
|
|
|
|
}
|
2020-02-13 22:13:16 -08:00
|
|
|
}
|
|
|
|
|
2020-02-15 19:32:26 -08:00
|
|
|
sfn PhysicsProcedure()
|
2020-02-13 22:13:16 -08:00
|
|
|
{
|
2020-02-15 19:32:26 -08:00
|
|
|
WorldCamera.UpdateCamera();
|
2020-02-14 23:21:27 -08:00
|
|
|
|
2020-02-15 19:32:26 -08:00
|
|
|
UpdateScreenspace();
|
2020-02-14 23:21:27 -08:00
|
|
|
|
2020-02-21 03:45:32 -08:00
|
|
|
Light.Update(gFloat(PhysicsDelta));
|
2020-02-16 22:28:24 -08:00
|
|
|
|
2020-02-20 22:18:07 -08:00
|
|
|
ObjectToView.Update();
|
2020-02-17 18:10:15 -08:00
|
|
|
|
2020-02-20 22:18:07 -08:00
|
|
|
UpdateWindowDeltaTitle();
|
2020-02-16 22:28:24 -08:00
|
|
|
}
|
2020-02-17 00:38:40 -08:00
|
|
|
|
2020-02-15 19:32:26 -08:00
|
|
|
sfn RenderProcedure() -> void
|
|
|
|
{
|
2020-02-21 03:45:32 -08:00
|
|
|
glfwSetWindowTitle(DefaultWindow, WindowTitle.str().c_str());
|
2020-02-17 00:38:40 -08:00
|
|
|
|
2020-02-21 03:45:32 -08:00
|
|
|
if (ShowLight)
|
|
|
|
{
|
|
|
|
Light.Render(WorldCamera.Perspective, WorldCamera.Viewport);
|
|
|
|
}
|
2020-02-16 22:28:24 -08:00
|
|
|
|
2020-02-20 22:18:07 -08:00
|
|
|
ObjectToView.Render(WorldCamera.Perspective, WorldCamera.Viewport, Light.GetPosition(), Light.GetColor());
|
2020-02-13 22:13:16 -08:00
|
|
|
}
|
2020-02-15 19:32:26 -08:00
|
|
|
|
2020-02-13 22:13:16 -08:00
|
|
|
|
2020-02-15 19:32:26 -08:00
|
|
|
// Runtime Execution: Default Execution
|
2020-02-13 22:13:16 -08:00
|
|
|
|
|
|
|
sfn Execute() -> ExitCode
|
|
|
|
{
|
2020-02-14 23:21:27 -08:00
|
|
|
PrepWorkspace();
|
2020-02-13 22:13:16 -08:00
|
|
|
|
2020-02-15 19:32:26 -08:00
|
|
|
Cycler(InputProcedure, PhysicsProcedure, RenderProcedure);
|
2020-02-13 22:13:16 -08:00
|
|
|
|
2020-02-20 22:18:07 -08:00
|
|
|
// TODO: There should be more to properly close...
|
|
|
|
|
|
|
|
DestoryWindow(DefaultWindow);
|
|
|
|
|
2020-02-15 19:32:26 -08:00
|
|
|
TerminateGLFW();
|
2020-02-13 22:13:16 -08:00
|
|
|
|
|
|
|
return ExitCode::Success;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-20 22:18:07 -08:00
|
|
|
// Currently only can do one execution route.
|
2020-02-13 22:13:16 -08:00
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
return int(Execution::Execute());
|
|
|
|
}
|
|
|
|
|