2020-02-13 22:13:16 -08:00
|
|
|
// Cpp STL
|
|
|
|
|
|
|
|
// Project
|
|
|
|
#include "DGL.hpp"
|
|
|
|
#include "TriangleRaw.hpp"
|
|
|
|
|
|
|
|
#include "Cpp_Alias.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
#include <glm/gtc/type_ptr.hpp>
|
|
|
|
#include <glm/gtc/type_ptr.hpp>
|
|
|
|
#include <glm/gtc/matrix_transform.hpp>
|
|
|
|
|
|
|
|
|
|
|
|
namespace Execution
|
|
|
|
{
|
|
|
|
// C++ STL
|
|
|
|
|
|
|
|
using std::thread;
|
2020-02-14 23:21:27 -08:00
|
|
|
|
|
|
|
|
2020-02-13 22:13:16 -08:00
|
|
|
|
|
|
|
template<typename Type>
|
|
|
|
using UPtr = std::unique_ptr<Type>;
|
|
|
|
|
|
|
|
template<typename Type, typename... ParamTypes>
|
|
|
|
sfn MakeUPtr(rRef(ParamTypes)... _params) -> UPtr<Type>
|
|
|
|
{
|
|
|
|
return std::make_unique<Type>(_params...);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// GL
|
|
|
|
|
2020-02-14 23:21:27 -08:00
|
|
|
using DGL::TimeValDec;
|
|
|
|
using DGL::Window ;
|
|
|
|
using DGL::Matrix ;
|
|
|
|
using DGL::Matrix4x4 ;
|
|
|
|
using DGL::Vector3 ;
|
|
|
|
using DGL::gFloat ;
|
2020-02-13 22:13:16 -08:00
|
|
|
|
|
|
|
|
|
|
|
bool Exist = true;
|
|
|
|
|
2020-02-14 23:21:27 -08:00
|
|
|
TimeValDec CycleStart, CycleEnd, DeltaTime, InputPollingInterval = 1.0f / 240.0f, PhysicsInterval = 1.0f / 120.0f, RenderInterval = 1.0f / 60.0f;
|
2020-02-13 22:13:16 -08:00
|
|
|
|
|
|
|
UPtr<thread> BasicLoop, BasicTimedLoop;
|
|
|
|
|
2020-02-14 23:21:27 -08:00
|
|
|
ptr<Window> DefaultWindow;
|
|
|
|
|
|
|
|
|
|
|
|
gFloat CamMoveSpeed = 3.0f, CamRotationSpeed = 1.0f;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum class CameraActions
|
|
|
|
{
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class EMovement
|
|
|
|
{
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename Device>
|
|
|
|
struct ActionBind
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
Delegate< Func<void>> Action;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct Keyboard
|
|
|
|
{
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ActionBinds
|
|
|
|
{
|
|
|
|
static ActionBind<Keyboard> MoveFoward;
|
|
|
|
};
|
|
|
|
|
2020-02-13 22:13:16 -08:00
|
|
|
|
|
|
|
|
|
|
|
// Testing
|
|
|
|
|
2020-02-14 23:21:27 -08:00
|
|
|
// Forward Declares
|
2020-02-13 22:13:16 -08:00
|
|
|
|
|
|
|
sfn RenderProcedure () -> void;
|
|
|
|
sfn PrepareRenderObjects() -> void;
|
|
|
|
|
|
|
|
sfn CreateWindow_BasicLoop()
|
|
|
|
{
|
2020-02-14 23:21:27 -08:00
|
|
|
DGL::InitalizeGLFW();
|
2020-02-13 22:13:16 -08:00
|
|
|
|
2020-02-14 23:21:27 -08:00
|
|
|
deduce windowObj = DGL::CreateWindow(720, 540, "Assignment 1: RawLoop", DGL::WindowedMode(), DGL::NotShared());
|
2020-02-13 22:13:16 -08:00
|
|
|
|
2020-02-14 23:21:27 -08:00
|
|
|
DGL::SetCurrentContext(windowObj);
|
2020-02-13 22:13:16 -08:00
|
|
|
|
2020-02-14 23:21:27 -08:00
|
|
|
DGL::RunBasicWindowLoop(windowObj);
|
2020-02-13 22:13:16 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
sfn CreateWindow_TimedRender()
|
|
|
|
{
|
2020-02-14 23:21:27 -08:00
|
|
|
DGL::InitalizeGLFW();
|
2020-02-13 22:13:16 -08:00
|
|
|
|
2020-02-14 23:21:27 -08:00
|
|
|
deduce windowObj = DGL::CreateWindow(720, 540, "Assignment 1: Timed Render", DGL::WindowedMode(), DGL::NotShared());
|
2020-02-13 22:13:16 -08:00
|
|
|
|
2020-02-14 23:21:27 -08:00
|
|
|
DGL::SetCurrentContext(windowObj);
|
2020-02-13 22:13:16 -08:00
|
|
|
|
2020-02-14 23:21:27 -08:00
|
|
|
DGL::InitalizeGLEW();
|
2020-02-13 22:13:16 -08:00
|
|
|
|
|
|
|
PrepareRenderObjects();
|
|
|
|
|
2020-02-14 23:21:27 -08:00
|
|
|
DGL::RunBasicWindowLoop_Timed(windowObj, 1.0 / 60.0, Address(RenderProcedure));
|
2020-02-13 22:13:16 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
sfn PrepareRenderObjects() -> void
|
|
|
|
{
|
|
|
|
RAW_SetupBuffers();
|
|
|
|
|
|
|
|
RAW_BindAndBufferDataToIDs();
|
|
|
|
|
2020-02-14 23:21:27 -08:00
|
|
|
DGL::LoadDefaultShaders();
|
2020-02-13 22:13:16 -08:00
|
|
|
|
2020-02-14 23:21:27 -08:00
|
|
|
DGL::FormatVertexAttributes<Vertex3>(VertexAttributeIndex, EDataType::Float, ZeroOffset(), Vertex3::ValueCount(), EBool::False);
|
2020-02-13 22:13:16 -08:00
|
|
|
|
2020-02-14 23:21:27 -08:00
|
|
|
DGL::BindBuffer(EBufferTarget::VertexAttributes, 0); // Dunno. Prob unbinding...
|
2020-02-13 22:13:16 -08:00
|
|
|
|
2020-02-14 23:21:27 -08:00
|
|
|
DGL::BindVertexArray(0);
|
2020-02-13 22:13:16 -08:00
|
|
|
}
|
|
|
|
|
2020-02-14 23:21:27 -08:00
|
|
|
using DGL::EFrameBuffer;
|
|
|
|
using DGL::LinearColor;
|
|
|
|
using DGL::DefaultSpace::WorldCamera;
|
|
|
|
|
|
|
|
using std::cout; using std::endl;
|
|
|
|
|
|
|
|
using DGL::KeyPressed;
|
|
|
|
using DGL::EKeyCodes;
|
|
|
|
|
|
|
|
using DGL::DefaultSpace::WorldCamera;
|
|
|
|
using DGL::EDirection;
|
|
|
|
|
|
|
|
|
|
|
|
struct CamShouldMove
|
|
|
|
{
|
|
|
|
bool Up, Down, Left, Right, Forward, Backward;
|
|
|
|
|
|
|
|
short int numActive;
|
|
|
|
};
|
|
|
|
|
|
|
|
CamShouldMove CamMoveRequests = { false, false, false, false, false, false, 0 };
|
|
|
|
|
|
|
|
double CursorX, CursorY;
|
|
|
|
|
|
|
|
using DGL::DefaultSpace::ScreenCenterWidth; using DGL::DefaultSpace::ScreenCenterHeight;
|
|
|
|
|
|
|
|
|
|
|
|
TimeValDec InputDelta = 0.0, PhysicsDelta = 0.0, RenderDelta = 0.0;
|
|
|
|
|
|
|
|
using DGL::DefaultSpace::Screenspace;
|
|
|
|
|
|
|
|
sfn Cycler(Delegate< Func<void, ptr<Window>> > _inputProcedure, Delegate< Func<void>> _renderProcedure)
|
2020-02-13 22:13:16 -08:00
|
|
|
{
|
|
|
|
while (Exist)
|
|
|
|
{
|
2020-02-14 23:21:27 -08:00
|
|
|
CycleStart = DGL::GetTime();
|
2020-02-13 22:13:16 -08:00
|
|
|
|
2020-02-14 23:21:27 -08:00
|
|
|
if (InputDelta >= InputPollingInterval)
|
2020-02-13 22:13:16 -08:00
|
|
|
{
|
2020-02-14 23:21:27 -08:00
|
|
|
DGL::PollEvents();
|
|
|
|
|
|
|
|
glfwGetCursorPos(DefaultWindow, Address(CursorX), Address(CursorY));
|
|
|
|
|
|
|
|
_inputProcedure(DefaultWindow);
|
|
|
|
|
|
|
|
DGL::ResetCursor(DefaultWindow, ScreenCenterWidth, ScreenCenterHeight);
|
2020-02-13 22:13:16 -08:00
|
|
|
|
2020-02-14 23:21:27 -08:00
|
|
|
InputDelta = 0.0;
|
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-14 23:21:27 -08:00
|
|
|
if (CamMoveRequests.Up ) WorldCamera.Move(EDirection::Up , CamMoveSpeed / CamMoveRequests.numActive, PhysicsDelta);
|
|
|
|
if (CamMoveRequests.Down ) WorldCamera.Move(EDirection::Down , CamMoveSpeed / CamMoveRequests.numActive, PhysicsDelta);
|
|
|
|
if (CamMoveRequests.Left ) WorldCamera.Move(EDirection::Left , CamMoveSpeed / CamMoveRequests.numActive, PhysicsDelta);
|
|
|
|
if (CamMoveRequests.Right ) WorldCamera.Move(EDirection::Right , CamMoveSpeed / CamMoveRequests.numActive, PhysicsDelta);
|
|
|
|
if (CamMoveRequests.Forward ) WorldCamera.Move(EDirection::Forward , CamMoveSpeed / CamMoveRequests.numActive, PhysicsDelta);
|
|
|
|
if (CamMoveRequests.Backward) WorldCamera.Move(EDirection::Backward, CamMoveSpeed / CamMoveRequests.numActive, PhysicsDelta);
|
|
|
|
|
|
|
|
WorldCamera.UpdateCamera();
|
|
|
|
|
|
|
|
//WorldCamera.Position.y = 0.0;
|
|
|
|
//WorldCamera.LookAtPosition.y = 0.0;
|
|
|
|
|
|
|
|
DGL::DefaultSpace::UpdateScreenspace();
|
|
|
|
|
|
|
|
CamMoveRequests = { false, false, false, false, false, false, 0 };
|
|
|
|
|
|
|
|
PhysicsDelta = 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (RenderDelta >= RenderInterval)
|
|
|
|
{
|
|
|
|
DGL::ClearBuffer(EFrameBuffer::Color, EFrameBuffer::Depth);
|
|
|
|
|
|
|
|
DGL::SetClearColor(LinearColor(0.12f, 0.12f, 0.12f, 1.0f));
|
|
|
|
|
2020-02-13 22:13:16 -08:00
|
|
|
_renderProcedure();
|
2020-02-14 23:21:27 -08:00
|
|
|
|
|
|
|
DGL::SwapBuffers(DefaultWindow);
|
|
|
|
|
|
|
|
RenderDelta = 0.0;
|
2020-02-13 22:13:16 -08:00
|
|
|
}
|
|
|
|
|
2020-02-14 23:21:27 -08:00
|
|
|
CycleEnd = DGL::GetTime();
|
|
|
|
|
|
|
|
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
|
|
|
using DGL::EMouseMode; using DGL::ECursorMode;
|
|
|
|
|
|
|
|
using DGL::DefaultSpace::ScreenCenterWidth; using DGL::DefaultSpace::ScreenCenterHeight;
|
|
|
|
|
|
|
|
sfn InputProcedure(ptr<Window> _currentWindowContext)
|
2020-02-13 22:13:16 -08:00
|
|
|
{
|
2020-02-14 23:21:27 -08:00
|
|
|
if (KeysPressed(_currentWindowContext, EKeyCodes::LeftShift, EKeyCodes::F1))
|
|
|
|
{
|
|
|
|
ECursorMode cursorMode = ECursorMode(GetMouseInputMode(DefaultWindow, EMouseMode::Cursor));
|
|
|
|
|
|
|
|
if (cursorMode == ECursorMode::Normal || cursorMode == ECursorMode::Hidden)
|
|
|
|
{
|
|
|
|
SetInputMode(_currentWindowContext, EMouseMode::Cursor, ECursorMode::Disable);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetInputMode(_currentWindowContext, EMouseMode::Cursor, ECursorMode::Normal);
|
|
|
|
}
|
|
|
|
}
|
2020-02-13 22:13:16 -08:00
|
|
|
|
2020-02-14 23:21:27 -08:00
|
|
|
if (CursorX != 0)//!= ScreenCenterWidth)
|
|
|
|
{
|
|
|
|
WorldCamera.Rotate(DGL::ERotationAxis::Yaw, CursorX * CamMoveSpeed, InputDelta);
|
|
|
|
|
|
|
|
//cout << "Cursor X: " << CursorX << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CursorY != 0)
|
|
|
|
{
|
|
|
|
WorldCamera.Rotate(DGL::ERotationAxis::Pitch, CursorY * CamMoveSpeed, InputDelta);
|
|
|
|
|
|
|
|
//cout << "Cursor Y: " << CursorX << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (KeyPressed(_currentWindowContext, EKeyCodes::E))
|
|
|
|
{
|
|
|
|
WorldCamera.Move(EDirection::Up, CamMoveSpeed, InputDelta);
|
|
|
|
|
|
|
|
CamMoveRequests.Up = true;
|
|
|
|
|
|
|
|
CamMoveRequests.numActive++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (KeyPressed(_currentWindowContext, EKeyCodes::Q))
|
|
|
|
{
|
|
|
|
WorldCamera.Move(EDirection::Down, CamMoveSpeed, InputDelta);
|
|
|
|
|
|
|
|
CamMoveRequests.Down = true;
|
|
|
|
|
|
|
|
CamMoveRequests.numActive++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (KeyPressed(_currentWindowContext, EKeyCodes::A))
|
|
|
|
{
|
|
|
|
WorldCamera.Move(EDirection::Left, CamMoveSpeed, InputDelta);
|
|
|
|
|
|
|
|
CamMoveRequests.Left = true;
|
|
|
|
|
|
|
|
CamMoveRequests.numActive++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (KeyPressed(_currentWindowContext, EKeyCodes::D))
|
|
|
|
{
|
|
|
|
WorldCamera.Move(EDirection::Right, CamMoveSpeed, InputDelta);
|
|
|
|
|
|
|
|
CamMoveRequests.Right = true;
|
|
|
|
|
|
|
|
CamMoveRequests.numActive++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (KeyPressed(_currentWindowContext, EKeyCodes::W))
|
|
|
|
{
|
|
|
|
WorldCamera.Move(EDirection::Forward, CamMoveSpeed, InputDelta);
|
|
|
|
|
|
|
|
CamMoveRequests.Forward = true;
|
|
|
|
|
|
|
|
CamMoveRequests.numActive++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (KeyPressed(_currentWindowContext, EKeyCodes::S))
|
|
|
|
{
|
|
|
|
WorldCamera.Move(EDirection::Backward, CamMoveSpeed, InputDelta);
|
|
|
|
|
|
|
|
CamMoveRequests.Backward = true;
|
|
|
|
|
|
|
|
CamMoveRequests.numActive++;
|
|
|
|
}
|
2020-02-13 22:13:16 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
sfn RenderProcedure() -> void
|
|
|
|
{
|
2020-02-14 23:21:27 -08:00
|
|
|
DGL::EnableVertexAttributeArray(VertexAttributeIndex);
|
|
|
|
|
|
|
|
DGL::SetPolygonMode(DGL::EFace::Front_and_Back, DGL::ERenderMode::Line);
|
2020-02-13 22:13:16 -08:00
|
|
|
|
2020-02-14 23:21:27 -08:00
|
|
|
DGL::DefaultSpace::WorldSpace = DGL::Rotate(DGL::DefaultSpace::WorldSpace, 0.0035f, Vector3(0.0f, 0.5f, 0.0f));
|
2020-02-13 22:13:16 -08:00
|
|
|
|
2020-02-14 23:21:27 -08:00
|
|
|
DGL::DefaultSpace::Screenspace = DGL::DefaultSpace::WorldCamera.Perspective * DGL::DefaultSpace::WorldCamera.Viewport * DGL::DefaultSpace::WorldSpace;
|
2020-02-13 22:13:16 -08:00
|
|
|
|
2020-02-14 23:21:27 -08:00
|
|
|
DGL::UseProgramShader(DGL::SimpleShader_Transformed);
|
2020-02-13 22:13:16 -08:00
|
|
|
|
2020-02-14 23:21:27 -08:00
|
|
|
DGL::SetUniformVariable_MatrixVariableArray(DGL::ScreenSpaceVarID, 1, DGL::EBool::False, Address(DGL::DefaultSpace::Screenspace[0][0]));
|
2020-02-13 22:13:16 -08:00
|
|
|
|
2020-02-14 23:21:27 -08:00
|
|
|
DGL::BindVertexArray(VertexArrayObj);
|
2020-02-13 22:13:16 -08:00
|
|
|
|
2020-02-14 23:21:27 -08:00
|
|
|
DGL::DrawArrays(DGL::EPrimitives::Triangles, 0, TriangleRaw::VertexCount());
|
2020-02-13 22:13:16 -08:00
|
|
|
|
2020-02-14 23:21:27 -08:00
|
|
|
DGL::DrawElements(DGL::EPrimitives::Triangles, 6, EDataType::UnsignedInt, ZeroOffset());
|
2020-02-13 22:13:16 -08:00
|
|
|
|
2020-02-14 23:21:27 -08:00
|
|
|
//GL::BindVertexArray(0);
|
|
|
|
|
|
|
|
DGL::DisableVertexAttributeArray(VertexAttributeIndex);
|
2020-02-13 22:13:16 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
sfn PrepWorkspace()
|
|
|
|
{
|
2020-02-14 23:21:27 -08:00
|
|
|
using DGL::DefaultSpace::ScreenWidth ;
|
|
|
|
using DGL::DefaultSpace::ScreenHeight;
|
|
|
|
|
|
|
|
DGL::InitalizeGLFW();
|
|
|
|
|
|
|
|
DefaultWindow = DGL::CreateWindow(ScreenWidth, ScreenHeight, "Assignment 1: Cam Movement Test", DGL::WindowedMode(), DGL::NotShared());
|
|
|
|
|
|
|
|
DGL::SetCurrentContext(DefaultWindow);
|
|
|
|
|
|
|
|
DGL::SetInputMode(DefaultWindow, DGL::EMouseMode::Cursor, DGL::ECursorMode::Disable);
|
2020-02-13 22:13:16 -08:00
|
|
|
|
2020-02-14 23:21:27 -08:00
|
|
|
DGL::ResetCursor(DefaultWindow, ScreenCenterWidth, ScreenCenterHeight);
|
|
|
|
|
|
|
|
if (DGL::CanUseRawMouse())
|
|
|
|
{
|
|
|
|
DGL::SetInputMode(DefaultWindow, DGL::EMouseMode::RawMouse, DGL::EBool::True);
|
|
|
|
}
|
|
|
|
|
|
|
|
DGL::InitalizeGLEW();
|
|
|
|
|
|
|
|
PrepareRenderObjects();
|
2020-02-13 22:13:16 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Runtime Execution: Loop must be specified here to use.
|
|
|
|
|
|
|
|
sfn Execute() -> ExitCode
|
|
|
|
{
|
2020-02-14 23:21:27 -08:00
|
|
|
PrepWorkspace();
|
2020-02-13 22:13:16 -08:00
|
|
|
|
2020-02-14 23:21:27 -08:00
|
|
|
Cycler(InputProcedure, RenderProcedure);
|
2020-02-13 22:13:16 -08:00
|
|
|
|
2020-02-14 23:21:27 -08:00
|
|
|
DGL::TerminateGLFW();
|
2020-02-13 22:13:16 -08:00
|
|
|
|
|
|
|
return ExitCode::Success;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
return int(Execution::Execute());
|
|
|
|
}
|
|
|
|
|