Added half cut tape.

This commit is contained in:
Edward R. Gonzalez 2020-04-06 17:40:20 -04:00
parent 5c0f8bf079
commit 3bda314253
12 changed files with 5135 additions and 818 deletions

802
Assignment_1_Execution.hpp Normal file
View File

@ -0,0 +1,802 @@
/*
Title : Execution
Author: Edward R. Gonzalez
Description:
This brings together the functionality I made in DGL and the Actions libraries to produce an OpenGL Workspace.
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.
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.
*/
#pragma once
// DGL
#include "DGL/DGL.hpp"
// Utility
#include "Actions.hpp"
// Non-Standard C++
#include "Cpp_Alias.hpp"
namespace Execution
{
inline namespace LibraryReferences
{
// DGL
using DGL::EAxis ;
using DGL::EBool ;
using DGL::ECursorMode ;
using DGL::EDirection ;
using DGL::EFrameBuffer ;
using DGL::EKeyCodes ;
using DGL::EMouseMode ;
using DGL::EPrimitives ;
using DGL::ERotationAxis;
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 ;
using DGL::BindVertexArray ;
using DGL::CanUseRawMouse ;
using DGL::ClearBuffer ;
using DGL::CreateWindow ;
using DGL::DestoryWindow ;
using DGL::DisableVertexAttributeArray;
using DGL::EnableDepth ;
using DGL::EnableVertexAttributeArray ;
using DGL::GetCursorPosition ;
using DGL::GetTime ;
using DGL::InitalizeGLEW ;
using DGL::InitalizeGLFW ;
using DGL::LoadDefaultShaders ;
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::SetWindowHeader ;
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;
}
enum class EModels
{
Bunny ,
Eight ,
Gargoyle ,
Hand ,
Horse ,
Sculpture,
Topology ,
Torus
};
// Globals
// Assignment 1
bool Exist = true; // Determines if the the execution should exit cycler.
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 / 60.0f, // Interval per second to complete the input process of the cycle.
PhysicsInterval = 1.0f / 60.0f, // Interval per second to complete the physics process of the cycle.
RenderInterval = 1.0f / 60.0f ; // Interval per second to complete the render process of the cycle.
Window* DefaultWindow; // Default window to use for execution.
double CursorX, CursorY; // Cursor axis position on the window.
bool CursorOff = true,
ShowLight = true,
RotateObj = true,
OrbitLight = true ;
gFloat CamMoveSpeed = 7.0f, // Rate at which the camera should move.
CamRotationSpeed = 27.0f ; // Rate at which the camera should rotate.
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.
ActionQueue ActionsToComplete; // Actions queue to run during the physics process of the cycle.
EModels CurrentModel = EModels::Bunny;
Model Bunny ("./Models/bunny.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" );
DGL::HE_Model BlenderTorus("./Models/torus_Blender.obj");
Material_Phong ObjectMaterial; // Material to use on the model.
Light_Basic Light ; // Hardcoded light. Rotates around object.
Entity_Basic ObjectToView; // Object that will be currently in the middle with the light source rotating.
string
windowTitle = "Assignment 1" ,
deltaStr = "Delta: " ,
inputDeltaStr = "Input Delta: " ,
physicsDeltaStr = "Physics Delta: " ,
renderDeltaStr = "RenderDeltaStr: " ;
stringstream WindowTitle;
// Functionality
// Input Action functions...
void ChangeModel()
{
if (CurrentModel == EModels::Torus)
{
CurrentModel = EModels::Bunny;
}
else
{
CurrentModel = EModels(int(CurrentModel) + 1);
}
switch (CurrentModel)
{
case EModels::Bunny:
{
if (not Bunny.Ready())
{
SetWindowHeader(DefaultWindow, "Assignment 1: Loading Bunny...");
Bunny.Load();
}
ObjectToView.SetModel(Bunny);
ObjectToView.SetScale(4.0f);
ObjectToView.SetPosition(Vector3(-0.05, -4.4f, 0));
ObjectMaterial.Color = DGL::Colors::White.Vector();
ObjectMaterial.Ambience = 0.300f ;
ObjectMaterial.Diffuse = 1.000f ;
ObjectMaterial.Specular = 0.910f ;
ObjectToView.SetMaterial(ObjectMaterial);
return;
}
case EModels::Eight:
{
if (not Eight.Ready())
{
SetWindowHeader(DefaultWindow, "Assignment 1: Loading Eight...");
Eight.Load();
}
ObjectToView.SetModel(Eight);
ObjectToView.SetScale(2.0f);
ObjectToView.SetPosition(Vector3(0, -1.0, 0));
ObjectMaterial.Color = DGL::Colors::Blue.Vector();
ObjectMaterial.Ambience = 0.112f ;
ObjectMaterial.Diffuse = 0.828f ;
ObjectMaterial.Specular = 0.421f ;
ObjectToView.SetMaterial(ObjectMaterial);
return;
}
case EModels::Gargoyle:
{
if (not Gargoyle.Ready())
{
SetWindowHeader(DefaultWindow, "Assignment 1: Loading Gargoyle...");
Gargoyle.Load();
}
ObjectToView.SetModel(Gargoyle);
ObjectToView.SetPosition(Vector3(-1, -5.4f, 0));
ObjectToView.SetScale(6.0f);
ObjectMaterial.Color = DGL::Colors::Red.Vector();
ObjectMaterial.Ambience = 0.001f ;
ObjectMaterial.Diffuse = 0.658f ;
ObjectMaterial.Specular = 0.821f ;
ObjectToView.SetMaterial(ObjectMaterial);
return;
}
case EModels::Hand:
{
if (not Hand.Ready())
{
SetWindowHeader(DefaultWindow, "Assignment 1: Loading Hand...");
Hand.Load();
}
ObjectToView.SetModel(Hand);
ObjectToView.SetScale(0.03f);
ObjectToView.SetPosition(Vector3(0, -1.1f, 0));
ObjectMaterial.Color = DGL::Colors::DarkTone.Vector();
ObjectMaterial.Ambience = 0.000f ;
ObjectMaterial.Diffuse = 1.000f ;
ObjectMaterial.Specular = 0.640f ;
ObjectToView.SetMaterial(ObjectMaterial);
SetClearColor(LinearColor(0.53f, 0.53f, 0.53f, 1.0f));
return;
}
case EModels::Horse:
{
if (not Horse.Ready())
{
SetWindowHeader(DefaultWindow, "Assignment 1: Loading Horse...");
Horse.Load();
}
ObjectToView.SetModel(Horse);
ObjectToView.SetScale(20.0f);
ObjectToView.Rotate(90.0f, EAxis::X);
ObjectToView.SetPosition(Vector3(0, 0.0f, 0));
ObjectMaterial.Color = DGL::Colors::Green.Vector();
ObjectMaterial.Ambience = 0.000f ;
ObjectMaterial.Diffuse = 1.000f ;
ObjectMaterial.Specular = 0.640f ;
ObjectToView.SetMaterial(ObjectMaterial);
SetClearColor(LinearColor(0.02f, 0.02f, 0.02f, 1.0f));
return;
}
case EModels::Sculpture:
{
if (not Sculpture.Ready())
{
SetWindowHeader(DefaultWindow, "Assignment 1: Loading Sculpture...");
Sculpture.Load();
}
ObjectToView.SetModel(Sculpture);
ObjectToView.SetScale(0.01f);
ObjectToView.Rotate(-90.0f, EAxis::X);
ObjectMaterial.Color = DGL::Colors::WarmSphia.Vector();
ObjectMaterial.Ambience = 0.112f ;
ObjectMaterial.Diffuse = 0.928f ;
ObjectMaterial.Specular = 0.21f ;
ObjectToView.SetMaterial(ObjectMaterial);
return;
}
case EModels::Topology:
{
if (not Topology.Ready())
{
SetWindowHeader(DefaultWindow, "Assignment 1: Loading Topology...");
Topology.Load();
}
ObjectToView.SetModel(Topology);
ObjectToView.SetScale(0.2f);
ObjectMaterial.Color = DGL::Colors::Coral.Vector();
ObjectMaterial.Ambience = 0.212f ;
ObjectMaterial.Diffuse = 0.728f ;
ObjectMaterial.Specular = 0.41f ;
ObjectToView.SetMaterial(ObjectMaterial);
return;
}
case EModels::Torus:
{
if (not Torus.Ready())
{
SetWindowHeader(DefaultWindow, "Assignment 1: Loading Torus...");
Torus.Load();
}
ObjectToView.SetModel(Torus);
ObjectToView.SetScale(1.0f);
ObjectMaterial.Color = DGL::Colors::Grey.Vector();
ObjectMaterial.Ambience = 0.170f ;
ObjectMaterial.Diffuse = 0.720f ;
ObjectMaterial.Specular = 0.100f ;
ObjectToView.SetMaterial(ObjectMaterial);
return;
}
}
}
void ToggleLight()
{
ShowLight ? ShowLight = false : ShowLight = true;
return;
}
void ToggleModelRotation()
{
RotateObj ? RotateObj = false : RotateObj = true;
return;
}
void ToogleLightOrbit()
{
OrbitLight ? OrbitLight = false : OrbitLight = true;
return;
}
void RotateCamera(ERotationAxis _rotationAxis, gFloat _rotationAmount, double _delta)
{
WorldCamera.Rotate(_rotationAxis, _rotationAmount, gFloat(_delta));
return;
}
void MoveCamera(EDirection _direction, gFloat _translationAmount, double _delta)
{
WorldCamera.Move(_direction, _translationAmount, gFloat(_delta));
return;
}
void ModifyCamSpeed(bool _isPositive, double _delta)
{
if (_isPositive)
{
CamMoveSpeed += CamMoveSpeed * gFloat(_delta);
return;
}
else
{
CamMoveSpeed -= CamMoveSpeed * gFloat(_delta);
return;
}
}
// End of common input functions...
void UpdateWindowDeltaTitle()
{
WindowTitle.str("");
WindowTitle
<< windowTitle << " "
<< deltaStr << DeltaTime << " "
<< inputDeltaStr << InputDelta << " "
<< physicsDeltaStr << PhysicsDelta << " "
<< renderDeltaStr << RenderDelta ;
}
// Currently Does everything required before entering the cycler.
void PrepWorkspace()
{
// Baseline
InitalizeGLFW();
DefaultWindow = CreateWindow(ScreenWidth, ScreenHeight, "Assignment 1: Loading Model...", WindowedMode(), NotShared());
SetCurrentContext(DefaultWindow);
InitalizeGLEW(); // Glew must initialize only after a context is set.
EnableDepth();
SetPolygonMode(DGL::EFace::Front_and_Back, DGL::ERenderMode::Fill);
// Cursor stuff
SetInputMode(DefaultWindow, DGL::EMouseMode::Cursor, DGL::ECursorMode::Disable);
ResetCursor(DefaultWindow, ScreenCenterWidth, ScreenCenterHeight);
if (CanUseRawMouse())
{
SetInputMode(DefaultWindow, DGL::EMouseMode::RawMouse, DGL::EBool::True);
}
// End of cursor stuff...
// Shaders
LoadDefaultShaders();
}
void SetupEntities()
{
Light.Load();
Bunny.Load();
ObjectMaterial.Color = DGL::Colors::White.Vector();
ObjectMaterial.Ambience = 0.300f;
ObjectMaterial.Diffuse = 1.000f;
ObjectMaterial.Specular = 0.910f;
ObjectToView = Entity_Basic(Bunny, ObjectMaterial);
ObjectToView.SetScale(4.0f);
ObjectToView.SetPosition(Vector3(-0.05, -4.4f, 0));
}
/*
Cycles the process of what to do while a window is open.
The input, physics, and render procedures can be specified with extra functionality by specifying delegates to those procedures.
Cycler is hardcoded to exit if escape key is pressed.
*/
void Cycler(const function< void(Window*)>& _inputProcedure, const function< void()>& _physicsProcedure, const function< void()>& _renderProcedure)
{
while (Exist)
{
CycleStart = GetTime();
if (InputDelta >= InputInterval)
{
PollEvents();
if (KeyPressed(DefaultWindow, EKeyCodes::Escape))
{
Exist = false;
}
GetCursorPosition(DefaultWindow, &CursorX, &CursorY);
_inputProcedure(DefaultWindow);
if (CursorOff)
{
ResetCursor(DefaultWindow, ScreenCenterWidth, ScreenCenterHeight);
}
}
if (PhysicsDelta >= PhysicsInterval)
{
while (ActionsToComplete.HasAction())
{
ActionsToComplete.DoNextAction();
}
_physicsProcedure();
PhysicsDelta = 0.0;
}
if (RenderDelta >= RenderInterval)
{
ClearBuffer(EFrameBuffer::Color, EFrameBuffer::Depth);
_renderProcedure();
SwapBuffers(DefaultWindow);
RenderDelta = 0.0;
}
if (InputDelta >= InputInterval)
{
InputDelta = 0.0;
}
CycleEnd = GetTime();
DeltaTime = CycleEnd - CycleStart;
InputDelta += DeltaTime;
PhysicsDelta += DeltaTime;
RenderDelta += DeltaTime;
}
return;
}
// Input functionality delegates (These are made due to a limitation with the actions implementation).
auto ChangeModelDelegate = function<decltype(ChangeModel )>(ChangeModel );
auto ToogleLightDelegate = function<decltype(ToggleLight )>(ToggleLight );
auto ToggleModelRotationDelegate = function<decltype(ToggleModelRotation)>(ToggleModelRotation);
auto ToggleLightOrbitDelegate = function<decltype(ToogleLightOrbit )>(ToogleLightOrbit );
auto RotateCamDelegate = function<decltype(RotateCamera )>(RotateCamera );
auto MoveCamDelegate = function<decltype(MoveCamera )>(MoveCamera );
auto ModifyCamSpeedDelegate = function<decltype(ModifyCamSpeed )>(ModifyCamSpeed );
auto SetPolyModeDelegate = function<decltype(SetPolygonMode )>(SetPolygonMode );
void InputProcedure(Window* _currentWindowContext)
{
static bool F1_Held = false,
F4_Held = false,
F5_Held = false,
H_Held = false,
M_Held = false ;
if (!KeyPressed(_currentWindowContext, EKeyCodes::F1)) F1_Held = false;
if (!KeyPressed(_currentWindowContext, EKeyCodes::F4)) F4_Held = false;
if (!KeyPressed(_currentWindowContext, EKeyCodes::F5)) F5_Held = false;
if (!KeyPressed(_currentWindowContext, EKeyCodes::H )) H_Held = false;
if (!KeyPressed(_currentWindowContext, EKeyCodes::M )) M_Held = false;
// TODO: Not necessary for now and throws memory error.
/*if (KeyPressed(_currentWindowContext, EKeyCodes::F1) && not F1_Held)
{
ECursorMode cursorMode = ECursorMode(GetMouseInputMode(DefaultWindow, EMouseMode::Cursor));
auto delegate = function<decltype(SetInputMode<ECursorMode>)>(SetInputMode<ECursorMode>);
auto delegateRaw = function<decltype(SetInputMode<EBool >)>(SetInputMode<EBool >);
if (cursorMode == ECursorMode::Normal || cursorMode == ECursorMode::Hidden)
{
ActionsToComplete.AddToQueue(delegate , _currentWindowContext, EMouseMode::Cursor , ECursorMode::Disable);
ActionsToComplete.AddToQueue(delegateRaw, _currentWindowContext, EMouseMode::RawMouse, EBool ::True );
CursorOff = true;
}
else
{
ActionsToComplete.AddToQueue(delegate , _currentWindowContext, EMouseMode::Cursor , ECursorMode::Normal);
ActionsToComplete.AddToQueue(delegateRaw, _currentWindowContext, EMouseMode::RawMouse, EBool ::False );
CursorOff = false;
}
F1_Held = true;
}*/
if (KeyPressed(_currentWindowContext, EKeyCodes::H) && not H_Held)
{
H_Held = true;
ActionsToComplete.AddToQueue(ToogleLightDelegate);
}
if (KeyPressed(_currentWindowContext, EKeyCodes::M) && not M_Held)
{
M_Held = true;
ActionsToComplete.AddToQueue(ChangeModelDelegate);
}
if (KeyPressed(_currentWindowContext, EKeyCodes::UpArrow))
{
ActionsToComplete.AddToQueue(ModifyCamSpeedDelegate, true, PhysicsDelta);
}
if (KeysPressed(_currentWindowContext, EKeyCodes::DnArrow))
{
ActionsToComplete.AddToQueue(ModifyCamSpeedDelegate, false, PhysicsDelta);
}
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);
}
if (KeyPressed(_currentWindowContext, EKeyCodes::F4) && not F4_Held)
{
ActionsToComplete.AddToQueue(ToggleModelRotationDelegate);
F4_Held = true;
}
if (KeyPressed(_currentWindowContext, EKeyCodes::F5) && not F5_Held)
{
ActionsToComplete.AddToQueue(ToggleLightOrbitDelegate);
F5_Held = true;
}
if (CursorOff)
{
if (CursorX != 0)
{
ActionsToComplete.AddToQueue(RotateCamDelegate, ERotationAxis::Yaw, gFloat(CursorX) * CamRotationSpeed, PhysicsDelta);
}
if (CursorY != 0)
{
ActionsToComplete.AddToQueue(RotateCamDelegate, ERotationAxis::Pitch, gFloat(CursorY) * CamRotationSpeed, PhysicsDelta);
}
}
if (KeyPressed(_currentWindowContext, EKeyCodes::E))
{
ActionsToComplete.AddToQueue(MoveCamDelegate, EDirection::Up, CamMoveSpeed, PhysicsDelta);
}
if (KeyPressed(_currentWindowContext, EKeyCodes::Q))
{
ActionsToComplete.AddToQueue(MoveCamDelegate, EDirection::Down, CamMoveSpeed, PhysicsDelta);
}
if (KeyPressed(_currentWindowContext, EKeyCodes::A))
{
ActionsToComplete.AddToQueue(MoveCamDelegate, EDirection::Left, CamMoveSpeed, PhysicsDelta);
}
if (KeyPressed(_currentWindowContext, EKeyCodes::D))
{
ActionsToComplete.AddToQueue(MoveCamDelegate, EDirection::Right, CamMoveSpeed, PhysicsDelta);
}
if (KeyPressed(_currentWindowContext, EKeyCodes::W))
{
ActionsToComplete.AddToQueue(MoveCamDelegate, EDirection::Forward, CamMoveSpeed, PhysicsDelta);
}
if (KeyPressed(_currentWindowContext, EKeyCodes::S))
{
ActionsToComplete.AddToQueue(MoveCamDelegate, EDirection::Backward, CamMoveSpeed, PhysicsDelta);
}
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);
}
return;
}
void PhysicsProcedure()
{
WorldCamera.UpdateCamera();
UpdateScreenspace();
if (OrbitLight)
{
Light.Update(gFloat(PhysicsDelta));
}
if (RotateObj)
{
ObjectToView.Rotate(-1.0f * gFloat(PhysicsDelta), EAxis::Y);
}
ObjectToView.Update();
UpdateWindowDeltaTitle();
return;
}
void RenderProcedure()
{
SetWindowHeader(DefaultWindow, WindowTitle.str());
if (ShowLight)
{
Light.Render(WorldCamera.Perspective, WorldCamera.Viewport);
}
ObjectToView.Render(WorldCamera.Perspective, WorldCamera.Viewport, Light.GetPosition(), Light.GetColor());
return;
}
// Runtime Execution: Default Execution
int Execute_Assignment1()
{
PrepWorkspace();
SetupEntities();
Cycler(InputProcedure, PhysicsProcedure, RenderProcedure);
// TODO: There should be more to properly close...
DestoryWindow(DefaultWindow);
TerminateGLFW();
return EXIT_SUCCESS;
}
}

View File

@ -0,0 +1,33 @@
#pragma once
#include "DGL/DGL.hpp"
#include "Cpp_Alias.hpp"
namespace Execution
{
inline namespace LibraryReferences
{
using DGL::HE_Model;
}
int Execute_Assignment2()
{
cout << "Assignment 2:" << endl << endl;
HE_Model BlenderTorus("./Models/torus_Blender.obj");
BlenderTorus.Load();
return EXIT_SUCCESS;
}
}

View File

@ -74,3 +74,8 @@ using std::thread;
using std::tuple;
using std::type_index;
using std::vector;
void DoNothing() {};

View File

@ -212,6 +212,7 @@ namespace DGL
rotation (Vector3(0.0f) ),
scale (Vector3(1.0f) ),
model (NULL ),
he_Model (NULL ),
transform(CoordSpace(1.0f))
{};
@ -220,6 +221,18 @@ namespace DGL
rotation (Vector3(0.0f) ),
scale (Vector3(1.0f) ),
model (&_model ),
he_Model (NULL ),
transform(CoordSpace(1.0f)),
material (_material )
//type (_type )
{};
Entity_Basic(HE_Model& _model, Material_Phong& _material) :
position (Vector3(0.0f) ),
rotation (Vector3(0.0f) ),
scale (Vector3(1.0f) ),
model (NULL ),
he_Model (&_model ),
transform(CoordSpace(1.0f)),
material (_material )
//type (_type )
@ -234,9 +247,18 @@ namespace DGL
{
model = &_model;
he_Model = NULL;
return;
}
void SetModel(HE_Model& _model)
{
he_Model = &_model;
model = NULL;
}
void SetScale(gFloat _scaleBy)
{
scale = Vector3(_scaleBy);
@ -295,7 +317,14 @@ namespace DGL
{
PhongShader::Use(_projection, _viewport, transform, _lightPosition,_lightColor, material);
if (model != NULL)
{
(*model).Render();
}
else
{
(*he_Model).Render();
}
PhongShader::Stop();
@ -307,6 +336,7 @@ namespace DGL
position = _entity.position ;
scale = _entity.scale ;
model = _entity.model ;
he_Model = _entity.he_Model ;
transform = _entity.transform;
material = _entity.material ;
@ -321,6 +351,7 @@ namespace DGL
Vector3 rotation ;
Vector3 scale ;
Model* model ;
HE_Model* he_Model;
CoordSpace transform;
Material_Phong material ;
};

View File

@ -13,6 +13,9 @@ Allows the management of loading and buffer/rendering models from wavefront obj
#include "DGL_Types.hpp"
#include "DGL_Space.hpp"
// OpenMesh
#include "OMesh/OMeshInterface.hpp"
// Non-Standard C++
#include "Cpp_Alias.hpp"
@ -69,17 +72,6 @@ namespace DGL
ComponentList comp;
};
struct Face
{
Vec3Int Vertexes;
};
using FaceList = std::vector<Face>;
struct FaceGenerator
{
using ComponentList = std::vector< gUInt>;
@ -107,7 +99,7 @@ namespace DGL
for (int index = 0; index < 3; index++)
{
generated.Vertexes.vec[index] = vertIndexes[index];
generated.vec[index] = vertIndexes[index];
if (index < 2)
{
@ -146,9 +138,9 @@ namespace DGL
for (int faceIndex = 0; faceIndex < faces.size(); faceIndex++)
{
int vertexIndex1 = faces[faceIndex].Vertexes.vec[0],
vertexIndex2 = faces[faceIndex].Vertexes.vec[1],
vertexIndex3 = faces[faceIndex].Vertexes.vec[2] ;
int vertexIndex1 = faces[faceIndex].vec[0],
vertexIndex2 = faces[faceIndex].vec[1],
vertexIndex3 = faces[faceIndex].vec[2] ;
Vector3 vert1 = verticies[vertexIndex1],
vert2 = verticies[vertexIndex2],
@ -470,4 +462,125 @@ namespace DGL
FaceList faces ;
VIndexList indicies ;
};
class HE_Model
{
using HE_Mesh = OMeshInterface::OMesh_HE;
public:
HE_Model(const string& _filePath) :
loaded (false ),
vertexArrayID (-1 ),
vertexBufferID (-1 ),
normalBuffferID(-1 ),
textureBufferID(-1 ),
elementBufferID(-1 ),
filePath (_filePath),
mesh ()
{}
void Buffer()
{
// Generate buffers
GenerateVertexBuffers(vertexArrayID , 1);
GenerateBuffers (vertexBufferID , 1);
GenerateBuffers (normalBuffferID, 1);
GenerateBuffers (elementBufferID, 1);
BindVertexArray(vertexArrayID);
// Vertex Position Buffering
BindBuffer(EBufferTarget::VertexAttributes, vertexBufferID);
const VertexList& verts = mesh.GetVerticies();
BufferData(verts[0], gSize(verts.size() * sizeof(Vector3)), EBufferTarget::VertexAttributes, EBufferUsage::StaticDraw);
FormatVertexAttributes<Vector3>(0, EDataType::Float, ZeroOffset(), 3, false);
EnableVertexAttributeArray(0);
// Normal Buffering
BindBuffer(EBufferTarget::VertexAttributes, normalBuffferID);
const VertexList& normals = mesh.GetFaceNormals();
BufferData(normals[0], gSize(normals.size() * sizeof(Vector3)), EBufferTarget::VertexAttributes, EBufferUsage::StaticDraw);
FormatVertexAttributes<Vector3>(1, EDataType::Float, ZeroOffset(), 3, false);
EnableVertexAttributeArray(1);
// Element Buffering
const FaceList& faces = mesh.GetFaces();
BindBuffer(EBufferTarget::VertexIndices, elementBufferID);
BufferData(faces[0], gSize(faces.size() * sizeof(Face)), EBufferTarget::VertexIndices, EBufferUsage::StaticDraw);
UnbindVertexArray(); // Unbind vertex array.
}
void Load()
{
mesh.Load(filePath);
Buffer();
}
bool Ready()
{
return loaded;
}
void Render()
{
BindVertexArray(vertexArrayID);
gInt SizeRef; GetBufferParameterIV(EBufferTarget::VertexIndices, EBufferParam::Size, SizeRef); SizeRef /= sizeof(gUInt);
DrawElements(EPrimitives::Triangles, SizeRef, EDataType::UnsignedInt, ZeroOffset());
UnbindVertexArray();
}
HE_Model& operator= (const HE_Model& _model)
{
loaded = _model.loaded;
vertexArrayID = _model.vertexArrayID ;
vertexBufferID = _model.vertexBufferID ;
normalBuffferID = _model.normalBuffferID;
textureBufferID = _model.textureBufferID;
elementBufferID = _model.elementBufferID;
filePath = _model.filePath;
mesh = _model.mesh;
return *this;
}
private:
bool loaded;
ID<VertexArray > vertexArrayID ;
ID<VertexBuffer > vertexBufferID ;
ID<NormalBuffer > normalBuffferID;
ID<TextureBuffer> textureBufferID;
ID<ElementBuffer> elementBufferID;
string filePath;
HE_Mesh mesh;
};
};

View File

@ -86,12 +86,13 @@ namespace DGL
struct Vec3Int
{
union
{
gUInt vec[3];
gUInt x, y, z;
};
//union
//{
//gUInt vec[3];
//gUInt x, y, z;
//};
};
//using Vec3Int = Generic::Vector3< gUInt >;
@ -111,6 +112,11 @@ namespace DGL
// DGL
using Face = Vec3Int;
using FaceList = std::vector<Face>;
using VecColor = Vector3;
struct LinearColor

View File

@ -1,805 +1,10 @@
/*
Title : Execution
Author: Edward R. Gonzalez
#include "Assignment_1_Execution.hpp"
#include "Assignment_2_Execution.hpp"
Description:
This brings together the functionality I made in DGL and the Actions libraries to produce an OpenGL Workspace.
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.
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.
*/
// DGL
#include "DGL/DGL.hpp"
// Utility
#include "Actions.hpp"
// Non-Standard C++
#include "Cpp_Alias.hpp"
namespace Execution
{
inline namespace LibraryReferences
{
// DGL
using DGL::EAxis ;
using DGL::EBool ;
using DGL::ECursorMode ;
using DGL::EDirection ;
using DGL::EFrameBuffer ;
using DGL::EKeyCodes ;
using DGL::EMouseMode ;
using DGL::EPrimitives ;
using DGL::ERotationAxis;
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 ;
using DGL::BindVertexArray ;
using DGL::CanUseRawMouse ;
using DGL::ClearBuffer ;
using DGL::CreateWindow ;
using DGL::DestoryWindow ;
using DGL::DisableVertexAttributeArray;
using DGL::EnableDepth ;
using DGL::EnableVertexAttributeArray ;
using DGL::GetCursorPosition ;
using DGL::GetTime ;
using DGL::InitalizeGLEW ;
using DGL::InitalizeGLFW ;
using DGL::LoadDefaultShaders ;
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::SetWindowHeader ;
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;
}
enum class EModels
{
Bunny ,
Eight ,
Gargoyle ,
Hand ,
Horse ,
Sculpture,
Topology ,
Torus
};
// Globals
bool Exist = true; // Determines if the the execution should exit cycler.
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 / 60.0f, // Interval per second to complete the input process of the cycle.
PhysicsInterval = 1.0f / 60.0f, // Interval per second to complete the physics process of the cycle.
RenderInterval = 1.0f / 60.0f ; // Interval per second to complete the render process of the cycle.
Window* DefaultWindow; // Default window to use for execution.
double CursorX, CursorY; // Cursor axis position on the window.
bool CursorOff = true,
ShowLight = true,
RotateObj = true,
OrbitLight = true ;
gFloat CamMoveSpeed = 7.0f, // Rate at which the camera should move.
CamRotationSpeed = 27.0f ; // Rate at which the camera should rotate.
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.
ActionQueue ActionsToComplete; // Actions queue to run during the physics process of the cycle.
EModels CurrentModel = EModels::Bunny;
Model Bunny ("./Models/bunny.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" );
Material_Phong ObjectMaterial; // Material to use on the model.
Light_Basic Light ; // Hardcoded light. Rotates around object.
Entity_Basic ObjectToView; // Object that will be currently in the middle with the light source rotating.
string
windowTitle = "Assignment 1" ,
deltaStr = "Delta: " ,
inputDeltaStr = "Input Delta: " ,
physicsDeltaStr = "Physics Delta: " ,
renderDeltaStr = "RenderDeltaStr: " ;
stringstream WindowTitle;
// Functionality
// Input Action functions...
void ChangeModel()
{
if (CurrentModel == EModels::Torus)
{
CurrentModel = EModels::Bunny;
}
else
{
CurrentModel = EModels(int(CurrentModel) + 1);
}
switch (CurrentModel)
{
case EModels::Bunny:
{
if (not Bunny.Ready())
{
SetWindowHeader(DefaultWindow, "Assignment 1: Loading Bunny...");
Bunny.Load();
}
ObjectToView.SetModel(Bunny);
ObjectToView.SetScale(4.0f);
ObjectToView.SetPosition(Vector3(-0.05, -4.4f, 0));
ObjectMaterial.Color = DGL::Colors::White.Vector();
ObjectMaterial.Ambience = 0.300f ;
ObjectMaterial.Diffuse = 1.000f ;
ObjectMaterial.Specular = 0.910f ;
ObjectToView.SetMaterial(ObjectMaterial);
return;
}
case EModels::Eight:
{
if (not Eight.Ready())
{
SetWindowHeader(DefaultWindow, "Assignment 1: Loading Eight...");
Eight.Load();
}
ObjectToView.SetModel(Eight);
ObjectToView.SetScale(2.0f);
ObjectToView.SetPosition(Vector3(0, -1.0, 0));
ObjectMaterial.Color = DGL::Colors::Blue.Vector();
ObjectMaterial.Ambience = 0.112f ;
ObjectMaterial.Diffuse = 0.828f ;
ObjectMaterial.Specular = 0.421f ;
ObjectToView.SetMaterial(ObjectMaterial);
return;
}
case EModels::Gargoyle:
{
if (not Gargoyle.Ready())
{
SetWindowHeader(DefaultWindow, "Assignment 1: Loading Gargoyle...");
Gargoyle.Load();
}
ObjectToView.SetModel(Gargoyle);
ObjectToView.SetPosition(Vector3(-1, -5.4f, 0));
ObjectToView.SetScale(6.0f);
ObjectMaterial.Color = DGL::Colors::Red.Vector();
ObjectMaterial.Ambience = 0.001f ;
ObjectMaterial.Diffuse = 0.658f ;
ObjectMaterial.Specular = 0.821f ;
ObjectToView.SetMaterial(ObjectMaterial);
return;
}
case EModels::Hand:
{
if (not Hand.Ready())
{
SetWindowHeader(DefaultWindow, "Assignment 1: Loading Hand...");
Hand.Load();
}
ObjectToView.SetModel(Hand);
ObjectToView.SetScale(0.03f);
ObjectToView.SetPosition(Vector3(0, -1.1f, 0));
ObjectMaterial.Color = DGL::Colors::DarkTone.Vector();
ObjectMaterial.Ambience = 0.000f ;
ObjectMaterial.Diffuse = 1.000f ;
ObjectMaterial.Specular = 0.640f ;
ObjectToView.SetMaterial(ObjectMaterial);
SetClearColor(LinearColor(0.53f, 0.53f, 0.53f, 1.0f));
return;
}
case EModels::Horse:
{
if (not Horse.Ready())
{
SetWindowHeader(DefaultWindow, "Assignment 1: Loading Horse...");
Horse.Load();
}
ObjectToView.SetModel(Horse);
ObjectToView.SetScale(20.0f);
ObjectToView.Rotate(90.0f, EAxis::X);
ObjectToView.SetPosition(Vector3(0, 0.0f, 0));
ObjectMaterial.Color = DGL::Colors::Green.Vector();
ObjectMaterial.Ambience = 0.000f ;
ObjectMaterial.Diffuse = 1.000f ;
ObjectMaterial.Specular = 0.640f ;
ObjectToView.SetMaterial(ObjectMaterial);
SetClearColor(LinearColor(0.02f, 0.02f, 0.02f, 1.0f));
return;
}
case EModels::Sculpture:
{
if (not Sculpture.Ready())
{
SetWindowHeader(DefaultWindow, "Assignment 1: Loading Sculpture...");
Sculpture.Load();
}
ObjectToView.SetModel(Sculpture);
ObjectToView.SetScale(0.01f);
ObjectToView.Rotate(-90.0f, EAxis::X);
ObjectMaterial.Color = DGL::Colors::WarmSphia.Vector();
ObjectMaterial.Ambience = 0.112f ;
ObjectMaterial.Diffuse = 0.928f ;
ObjectMaterial.Specular = 0.21f ;
ObjectToView.SetMaterial(ObjectMaterial);
return;
}
case EModels::Topology:
{
if (not Topology.Ready())
{
SetWindowHeader(DefaultWindow, "Assignment 1: Loading Topology...");
Topology.Load();
}
ObjectToView.SetModel(Topology);
ObjectToView.SetScale(0.2f);
ObjectMaterial.Color = DGL::Colors::Coral.Vector();
ObjectMaterial.Ambience = 0.212f ;
ObjectMaterial.Diffuse = 0.728f ;
ObjectMaterial.Specular = 0.41f ;
ObjectToView.SetMaterial(ObjectMaterial);
return;
}
case EModels::Torus:
{
if (not Torus.Ready())
{
SetWindowHeader(DefaultWindow, "Assignment 1: Loading Torus...");
Torus.Load();
}
ObjectToView.SetModel(Torus);
ObjectToView.SetScale(1.0f);
ObjectMaterial.Color = DGL::Colors::Grey.Vector();
ObjectMaterial.Ambience = 0.170f ;
ObjectMaterial.Diffuse = 0.720f ;
ObjectMaterial.Specular = 0.100f ;
ObjectToView.SetMaterial(ObjectMaterial);
return;
}
}
}
void ToggleLight()
{
ShowLight ? ShowLight = false : ShowLight = true;
return;
}
void ToggleModelRotation()
{
RotateObj ? RotateObj = false : RotateObj = true;
return;
}
void ToogleLightOrbit()
{
OrbitLight ? OrbitLight = false : OrbitLight = true;
return;
}
void RotateCamera(ERotationAxis _rotationAxis, gFloat _rotationAmount, double _delta)
{
WorldCamera.Rotate(_rotationAxis, _rotationAmount, gFloat(_delta));
return;
}
void MoveCamera(EDirection _direction, gFloat _translationAmount, double _delta)
{
WorldCamera.Move(_direction, _translationAmount, gFloat(_delta));
return;
}
void ModifyCamSpeed(bool _isPositive, double _delta)
{
if (_isPositive)
{
CamMoveSpeed += CamMoveSpeed * gFloat(_delta);
return;
}
else
{
CamMoveSpeed -= CamMoveSpeed * gFloat(_delta);
return;
}
}
// End of common input functions...
void UpdateWindowDeltaTitle()
{
WindowTitle.str("");
WindowTitle
<< windowTitle << " "
<< deltaStr << DeltaTime << " "
<< inputDeltaStr << InputDelta << " "
<< physicsDeltaStr << PhysicsDelta << " "
<< renderDeltaStr << RenderDelta ;
}
// Currently Does everything required before entering the cycler.
void PrepWorkspace()
{
// Baseline
InitalizeGLFW();
DefaultWindow = CreateWindow(ScreenWidth, ScreenHeight, "Assignment 1: Loading Model...", WindowedMode(), NotShared());
SetCurrentContext(DefaultWindow);
InitalizeGLEW(); // Glew must initialize only after a context is set.
EnableDepth();
SetPolygonMode(DGL::EFace::Front_and_Back, DGL::ERenderMode::Fill);
// Cursor stuff
SetInputMode(DefaultWindow, DGL::EMouseMode::Cursor, DGL::ECursorMode::Disable);
ResetCursor(DefaultWindow, ScreenCenterWidth, ScreenCenterHeight);
if (CanUseRawMouse())
{
SetInputMode(DefaultWindow, DGL::EMouseMode::RawMouse, DGL::EBool::True);
}
// End of cursor stuff...
// Shaders
LoadDefaultShaders();
// Entities
Light.Load();
Bunny.Load();
ObjectMaterial.Color = DGL::Colors::White.Vector();
ObjectMaterial.Ambience = 0.300f ;
ObjectMaterial.Diffuse = 1.000f ;
ObjectMaterial.Specular = 0.910f ;
ObjectToView = Entity_Basic(Bunny, ObjectMaterial);
ObjectToView.SetScale(4.0f);
ObjectToView.SetPosition(Vector3(-0.05, -4.4f, 0));
}
/*
Cycles the process of what to do while a window is open.
The input, physics, and render procedures can be specified with extra functionality by specifying delegates to those procedures.
Cycler is hardcoded to exit if escape key is pressed.
*/
void Cycler(const function< void(Window*)>& _inputProcedure, const function< void()>& _physicsProcedure, const function< void()>& _renderProcedure)
{
while (Exist)
{
CycleStart = GetTime();
if (InputDelta >= InputInterval)
{
PollEvents();
if (KeyPressed(DefaultWindow, EKeyCodes::Escape))
{
Exist = false;
}
GetCursorPosition(DefaultWindow, &CursorX, &CursorY);
_inputProcedure(DefaultWindow);
if (CursorOff)
{
ResetCursor(DefaultWindow, ScreenCenterWidth, ScreenCenterHeight);
}
}
if (PhysicsDelta >= PhysicsInterval)
{
while (ActionsToComplete.HasAction())
{
ActionsToComplete.DoNextAction();
}
_physicsProcedure();
PhysicsDelta = 0.0;
}
if (RenderDelta >= RenderInterval)
{
ClearBuffer(EFrameBuffer::Color, EFrameBuffer::Depth);
_renderProcedure();
SwapBuffers(DefaultWindow);
RenderDelta = 0.0;
}
if (InputDelta >= InputInterval)
{
InputDelta = 0.0;
}
CycleEnd = GetTime();
DeltaTime = CycleEnd - CycleStart;
InputDelta += DeltaTime;
PhysicsDelta += DeltaTime;
RenderDelta += DeltaTime;
}
return;
}
// Input functionality delegates (These are made due to a limitation with the actions implementation).
auto ChangeModelDelegate = function<decltype(ChangeModel )>(ChangeModel );
auto ToogleLightDelegate = function<decltype(ToggleLight )>(ToggleLight );
auto ToggleModelRotationDelegate = function<decltype(ToggleModelRotation)>(ToggleModelRotation);
auto ToggleLightOrbitDelegate = function<decltype(ToogleLightOrbit )>(ToogleLightOrbit );
auto RotateCamDelegate = function<decltype(RotateCamera )>(RotateCamera );
auto MoveCamDelegate = function<decltype(MoveCamera )>(MoveCamera );
auto ModifyCamSpeedDelegate = function<decltype(ModifyCamSpeed )>(ModifyCamSpeed );
auto SetPolyModeDelegate = function<decltype(SetPolygonMode )>(SetPolygonMode );
void InputProcedure(Window* _currentWindowContext)
{
static bool F1_Held = false,
F4_Held = false,
F5_Held = false,
H_Held = false,
M_Held = false ;
if (!KeyPressed(_currentWindowContext, EKeyCodes::F1)) F1_Held = false;
if (!KeyPressed(_currentWindowContext, EKeyCodes::F4)) F4_Held = false;
if (!KeyPressed(_currentWindowContext, EKeyCodes::F5)) F5_Held = false;
if (!KeyPressed(_currentWindowContext, EKeyCodes::H )) H_Held = false;
if (!KeyPressed(_currentWindowContext, EKeyCodes::M )) M_Held = false;
// TODO: Not necessary for now and throws memory error.
/*if (KeyPressed(_currentWindowContext, EKeyCodes::F1) && not F1_Held)
{
ECursorMode cursorMode = ECursorMode(GetMouseInputMode(DefaultWindow, EMouseMode::Cursor));
auto delegate = function<decltype(SetInputMode<ECursorMode>)>(SetInputMode<ECursorMode>);
auto delegateRaw = function<decltype(SetInputMode<EBool >)>(SetInputMode<EBool >);
if (cursorMode == ECursorMode::Normal || cursorMode == ECursorMode::Hidden)
{
ActionsToComplete.AddToQueue(delegate , _currentWindowContext, EMouseMode::Cursor , ECursorMode::Disable);
ActionsToComplete.AddToQueue(delegateRaw, _currentWindowContext, EMouseMode::RawMouse, EBool ::True );
CursorOff = true;
}
else
{
ActionsToComplete.AddToQueue(delegate , _currentWindowContext, EMouseMode::Cursor , ECursorMode::Normal);
ActionsToComplete.AddToQueue(delegateRaw, _currentWindowContext, EMouseMode::RawMouse, EBool ::False );
CursorOff = false;
}
F1_Held = true;
}*/
if (KeyPressed(_currentWindowContext, EKeyCodes::H) && not H_Held)
{
H_Held = true;
ActionsToComplete.AddToQueue(ToogleLightDelegate);
}
if (KeyPressed(_currentWindowContext, EKeyCodes::M) && not M_Held)
{
M_Held = true;
ActionsToComplete.AddToQueue(ChangeModelDelegate);
}
if (KeyPressed(_currentWindowContext, EKeyCodes::UpArrow))
{
ActionsToComplete.AddToQueue(ModifyCamSpeedDelegate, true, PhysicsDelta);
}
if (KeysPressed(_currentWindowContext, EKeyCodes::DnArrow))
{
ActionsToComplete.AddToQueue(ModifyCamSpeedDelegate, false, PhysicsDelta);
}
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);
}
if (KeyPressed(_currentWindowContext, EKeyCodes::F4) && not F4_Held)
{
ActionsToComplete.AddToQueue(ToggleModelRotationDelegate);
F4_Held = true;
}
if (KeyPressed(_currentWindowContext, EKeyCodes::F5) && not F5_Held)
{
ActionsToComplete.AddToQueue(ToggleLightOrbitDelegate);
F5_Held = true;
}
if (CursorOff)
{
if (CursorX != 0)
{
ActionsToComplete.AddToQueue(RotateCamDelegate, ERotationAxis::Yaw, gFloat(CursorX) * CamRotationSpeed, PhysicsDelta);
}
if (CursorY != 0)
{
ActionsToComplete.AddToQueue(RotateCamDelegate, ERotationAxis::Pitch, gFloat(CursorY) * CamRotationSpeed, PhysicsDelta);
}
}
if (KeyPressed(_currentWindowContext, EKeyCodes::E))
{
ActionsToComplete.AddToQueue(MoveCamDelegate, EDirection::Up, CamMoveSpeed, PhysicsDelta);
}
if (KeyPressed(_currentWindowContext, EKeyCodes::Q))
{
ActionsToComplete.AddToQueue(MoveCamDelegate, EDirection::Down, CamMoveSpeed, PhysicsDelta);
}
if (KeyPressed(_currentWindowContext, EKeyCodes::A))
{
ActionsToComplete.AddToQueue(MoveCamDelegate, EDirection::Left, CamMoveSpeed, PhysicsDelta);
}
if (KeyPressed(_currentWindowContext, EKeyCodes::D))
{
ActionsToComplete.AddToQueue(MoveCamDelegate, EDirection::Right, CamMoveSpeed, PhysicsDelta);
}
if (KeyPressed(_currentWindowContext, EKeyCodes::W))
{
ActionsToComplete.AddToQueue(MoveCamDelegate, EDirection::Forward, CamMoveSpeed, PhysicsDelta);
}
if (KeyPressed(_currentWindowContext, EKeyCodes::S))
{
ActionsToComplete.AddToQueue(MoveCamDelegate, EDirection::Backward, CamMoveSpeed, PhysicsDelta);
}
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);
}
return;
}
void PhysicsProcedure()
{
WorldCamera.UpdateCamera();
UpdateScreenspace();
if (OrbitLight)
{
Light.Update(gFloat(PhysicsDelta));
}
if (RotateObj)
{
ObjectToView.Rotate(-1.0f * gFloat(PhysicsDelta), EAxis::Y);
}
ObjectToView.Update();
UpdateWindowDeltaTitle();
return;
}
void RenderProcedure()
{
SetWindowHeader(DefaultWindow, WindowTitle.str());
if (ShowLight)
{
Light.Render(WorldCamera.Perspective, WorldCamera.Viewport);
}
ObjectToView.Render(WorldCamera.Perspective, WorldCamera.Viewport, Light.GetPosition(), Light.GetColor());
return;
}
// Runtime Execution: Default Execution
int Execute()
{
PrepWorkspace();
Cycler(InputProcedure, PhysicsProcedure, RenderProcedure);
// TODO: There should be more to properly close...
DestoryWindow(DefaultWindow);
TerminateGLFW();
return EXIT_SUCCESS;
}
}
// Currently only can do one execution route.
int main(void)
{
return Execution::Execute();
return Execution::Execute_Assignment2();
}

10
Models/torus_Blender.mtl Normal file
View File

@ -0,0 +1,10 @@
# Blender MTL File: 'None'
# Material Count: 1
newmtl None
Ns 0
Ka 0.000000 0.000000 0.000000
Kd 0.8 0.8 0.8
Ks 0.8 0.8 0.8
d 1
illum 2

3897
Models/torus_Blender.obj Normal file

File diff suppressed because it is too large Load Diff

209
OMesh/OMeshInterface.hpp Normal file
View File

@ -0,0 +1,209 @@
#pragma once
// DGL
#include "DGL/DGL_Types.hpp"
// OpenMesh
#include <OpenMesh/Core/IO/MeshIO.hh>
#include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh>
#include <OpenMesh/Core/Mesh/PolyMesh_ArrayKernelT.hh>
// C++
#include "Cpp_Alias.hpp"
namespace OMeshInterface
{
inline namespace LibraryReferences
{
// DGL
using FaceGL = DGL::Face ;
using FaceList = DGL::FaceList ;
using Vector3 = DGL::Vector3 ;
using VertexList = DGL::VertexList;
// OpenMesh
using EdgeHandle = OpenMesh::EdgeHandle ;
using HE_Mesh = OpenMesh::TriMesh_ArrayKernelT<> ;
using HE_MeshPoly = OpenMesh::PolyMesh_ArrayKernelT<>;
using FaceHandle = OpenMesh::FaceHandle ;
using HalfEdgeHandle = OpenMesh::HalfedgeHandle ;
using IO_Options = OpenMesh::IO::Options ;
using VertexHandle = OpenMesh::VertexHandle ;
using Vertex = OpenMesh::ArrayKernel::Vertex ;
using OpenMesh::IO::read_mesh;
// Second Order Aliases
using Point = HE_Mesh::Point;
using Edge = HE_Mesh::Edge ;
using EdgeList = vector<Edge>;
using EdgeHandles = vector<EdgeHandle >;
using FaceHandles = vector<FaceHandle >;
using HalfEdgeHandles = vector<HalfEdgeHandle>;
using VertHandles = vector<VertexHandle >;
}
class OMesh_HE
{
public:
OMesh_HE() {}
void Load(string _filePath)
{
IO_Options loadOptions;
bool loadResult, hasFaceNormals, hasVertexNormals;
oMeshObj.request_vertex_normals();
oMeshObj.request_face_normals ();
loadResult = read_mesh(oMeshObj, _filePath, loadOptions);
if (loadResult == false)
{
throw std::runtime_error("OMesh_HE: Failed to load the mesh.");
}
hasFaceNormals = loadOptions.check(IO_Options::FaceNormal );
hasVertexNormals = loadOptions.check(IO_Options::VertexNormal);
if (!hasVertexNormals)
{
oMeshObj.update_vertex_normals ();
}
if (!hasFaceNormals)
{
oMeshObj.update_face_normals ();
}
GenerateVertexList ();
GenerateVertexNormalList();
GenerateFaceNormalList ();
GenerateVertexEdgeList ();
GenerateFaceList ();
return;
}
const VertexList& GetVerticies() const
{
return verticies;
}
const VertexList& GetVertNormals() const
{
return vertNormals;
}
const EdgeList& GetVertEdges() const
{
return edges;
}
const FaceList& GetFaces() const
{
return faces;
}
const VertexList& GetFaceNormals() const
{
return faceNormals;
}
protected:
void GenerateVertexList()
{
using VertIter = HE_Mesh::VertexIter;
for (VertIter element = oMeshObj.vertices_begin(); element != oMeshObj.vertices_end(); element++)
{
auto vertex = oMeshObj.point(*element);
verticies.push_back(Vector3(vertex[0], vertex[1], vertex[2]));
}
return;
}
void GenerateVertexNormalList()
{
using VertIter = HE_Mesh::VertexIter;
for (VertIter element = oMeshObj.vertices_begin(); element != oMeshObj.vertices_end(); element++)
{
auto normal = oMeshObj.normal(*element);
vertNormals.push_back(Vector3(normal[0], normal[1], normal[2]));
}
return;
}
void GenerateFaceNormalList()
{
using FaceIter = HE_Mesh::FaceIter;
for (FaceIter faceElem = oMeshObj.faces_begin(); faceElem != oMeshObj.faces_end(); faceElem++)
{
auto normal = oMeshObj.normal(*faceElem);
faceNormals.push_back(Vector3(normal[0], normal[1], normal[2]));
}
}
void GenerateVertexEdgeList()
{
using EdgeIter = HE_Mesh::EdgeIter;
for (EdgeIter element = oMeshObj.edges_begin(); element != oMeshObj.edges_begin(); element++)
{
using OEdge = decltype(oMeshObj.edge(*element));
OEdge edge = oMeshObj.edge(*element);
edges.push_back(edge);
}
}
void GenerateFaceList()
{
using FaceIterElem = decltype(oMeshObj.faces_begin());
for (FaceIterElem faceElement = oMeshObj.faces_begin(); faceElement != oMeshObj.faces_end(); faceElement++)
{
FaceGL face;
int index = 0;
using FaceVertexIter = HE_Mesh::FaceVertexIter;
for (FaceVertexIter vertElement = oMeshObj.fv_begin(*faceElement); vertElement != oMeshObj.fv_end(*faceElement); vertElement++, index++)
{
face.vec[index] = vertElement->idx();
}
faces.push_back(face);
}
return;
}
HE_Mesh oMeshObj;
VertexList verticies ;
VertexList vertNormals;
VertexList faceNormals;
EdgeList edges ;
FaceList faces ;
};
}

View File

@ -1,5 +1,7 @@
#version 330 core
out vec4 FragColor;
in vec3 FragPosition ;

View File

@ -1,9 +1,13 @@
#version 330 core
#define VertexIndex 0
#define NormalIndex 1
#define TextureIndex 2
layout (location = VertexIndex ) in vec3 VertPosition;
layout (location = NormalIndex ) in vec3 VertNormal ;
layout (location = TextureIndex) in vec3 VertTexture ;