Missing tape and some extra polish.

This commit is contained in:
Edward R. Gonzalez 2020-02-27 00:00:19 -05:00
parent 7dfb188fd2
commit f9c80fc326
4 changed files with 224 additions and 69 deletions

View File

@ -25,10 +25,14 @@ namespace DGL
{ {
namespace Colors namespace Colors
{ {
LinearColor Blue (0.3f , 0.3f , 0.6f , 1.0f);
LinearColor Coral (1.0f , 0.5f , 0.31f, 1.0f); LinearColor Coral (1.0f , 0.5f , 0.31f, 1.0f);
LinearColor Grey (0.60f, 0.60f, 0.60f, 1.0f); LinearColor DarkTone (0.21f , 0.21f, 0.21f, 1.0f);
LinearColor WarmSphia(0.54f, 0.52f, 0.5f , 1.0f); LinearColor Green (0.10f , 0.60f, 0.20f, 1.0f);
LinearColor White (1.0f , 1.0f , 1.0f , 1.0f); LinearColor Grey (0.60f , 0.60f, 0.60f, 1.0f);
LinearColor Red (0.436f, 0.04f, 0.01f, 1.0f);
LinearColor WarmSphia(0.54f , 0.52f, 0.5f , 1.0f);
LinearColor White (0.8f , 0.80f, 0.80f, 1.0f);
} }
@ -205,6 +209,7 @@ namespace DGL
public: public:
Entity_Basic() : Entity_Basic() :
position (Vector3(0.0f) ), position (Vector3(0.0f) ),
rotation (Vector3(0.0f) ),
scale (Vector3(1.0f) ), scale (Vector3(1.0f) ),
model (NULL ), model (NULL ),
transform(CoordSpace(1.0f)) transform(CoordSpace(1.0f))
@ -212,6 +217,7 @@ namespace DGL
Entity_Basic(Model& _model, Material_Phong& _material) : Entity_Basic(Model& _model, Material_Phong& _material) :
position (Vector3(0.0f) ), position (Vector3(0.0f) ),
rotation (Vector3(0.0f) ),
scale (Vector3(1.0f) ), scale (Vector3(1.0f) ),
model (&_model ), model (&_model ),
transform(CoordSpace(1.0f)), transform(CoordSpace(1.0f)),
@ -219,6 +225,11 @@ namespace DGL
//type (_type ) //type (_type )
{}; {};
void SetMaterial(Material_Phong& _material)
{
material = _material;
}
void SetModel(Model& _model) void SetModel(Model& _model)
{ {
model = &_model; model = &_model;
@ -230,12 +241,6 @@ namespace DGL
{ {
scale = Vector3(_scaleBy); scale = Vector3(_scaleBy);
transform = CoordSpace(1.0f);
transform = Translate(transform, position);
transform = Scale(transform, scale);
return; return;
} }
@ -243,18 +248,47 @@ namespace DGL
{ {
position = _position; position = _position;
transform = CoordSpace(1.0f); return;
}
transform = Translate(transform, position); void Rotate(gFloat _rotationAmount, EAxis _axis)
{
switch (_axis)
{
case EAxis::X:
{
rotation.x += _rotationAmount;
transform = Scale(transform, scale); break;
}
case EAxis::Y:
{
rotation.y += _rotationAmount;
break;
}
case EAxis::Z:
{
rotation.z += _rotationAmount;
break;
}
}
return; return;
} }
void Update() void Update()
{ {
transform = CoordSpace(1.0f);
transform = DGL::Translate(transform, position);
transform = DGL::Rotate(transform, rotation.x, Vector3(1, 0, 0));
transform = DGL::Rotate(transform, rotation.y, Vector3(0, 1, 0));
transform = DGL::Rotate(transform, rotation.z, Vector3(0, 0, 1));
transform = DGL::Scale(transform, scale);
} }
void Render(const CoordSpace& _projection, const CoordSpace& _viewport, const Vector3& _lightPosition, const VecColor& _lightColor) void Render(const CoordSpace& _projection, const CoordSpace& _viewport, const Vector3& _lightPosition, const VecColor& _lightColor)
@ -284,9 +318,10 @@ namespace DGL
// EEntityType type; // EEntityType type;
Vector3 position ; Vector3 position ;
Vector3 rotation ;
Vector3 scale ; Vector3 scale ;
Model* model ; Model* model ;
CoordSpace transform ; CoordSpace transform;
Material_Phong material ; Material_Phong material ;
}; };
} }

View File

@ -127,6 +127,8 @@ namespace DGL
F1 = GLFW_KEY_F1 , F1 = GLFW_KEY_F1 ,
F2 = GLFW_KEY_F2 , F2 = GLFW_KEY_F2 ,
F3 = GLFW_KEY_F3 , F3 = GLFW_KEY_F3 ,
F4 = GLFW_KEY_F4 ,
F5 = GLFW_KEY_F5 ,
A = GLFW_KEY_A , A = GLFW_KEY_A ,
D = GLFW_KEY_D , D = GLFW_KEY_D ,
E = GLFW_KEY_E , E = GLFW_KEY_E ,

View File

@ -151,7 +151,7 @@ namespace DGL
void InitalizeGLEW() void InitalizeGLEW()
{ {
// If using GLEW version 1.13 or earlier // If using GLEW version 1.13 or earlier
//glewExperimental = true; glewExperimental = true;
std::cout << "Initializing Glew Version: " << glewGetString(GLEW_VERSION) << std::endl; std::cout << "Initializing Glew Version: " << glewGetString(GLEW_VERSION) << std::endl;

View File

@ -31,6 +31,7 @@ namespace Execution
{ {
// DGL // DGL
using DGL::EAxis ;
using DGL::EBool ; using DGL::EBool ;
using DGL::ECursorMode ; using DGL::ECursorMode ;
using DGL::EDirection ; using DGL::EDirection ;
@ -101,6 +102,7 @@ namespace Execution
Eight , Eight ,
Gargoyle , Gargoyle ,
Hand , Hand ,
Horse ,
Sculpture, Sculpture,
Topology , Topology ,
Torus Torus
@ -114,16 +116,18 @@ namespace Execution
TimeValDec CycleStart , // Snapshot of cycle loop start time. TimeValDec CycleStart , // Snapshot of cycle loop start time.
CycleEnd , // Snapshot of cycle loop end time. CycleEnd , // Snapshot of cycle loop end time.
DeltaTime , // Delta between last cycle start and end. DeltaTime , // Delta between last cycle start and end.
InputInterval = 1.0f / 144.0f, // Interval per second to complete the input process of the cycle. InputInterval = 1.0f / 60.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. PhysicsInterval = 1.0f / 60.0f, // Interval per second to complete the physics process of the cycle.
RenderInterval = 1.0f / 144.0f ; // Interval per second to complete the render 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. Window* DefaultWindow; // Default window to use for execution.
double CursorX, CursorY; // Cursor axis position on the window. double CursorX, CursorY; // Cursor axis position on the window.
bool CursorOff = true, bool CursorOff = true,
ShowLight = true ; ShowLight = true,
RotateObj = true,
OrbitLight = true ;
gFloat CamMoveSpeed = 7.0f, // Rate at which the camera should move. gFloat CamMoveSpeed = 7.0f, // Rate at which the camera should move.
CamRotationSpeed = 27.0f ; // Rate at which the camera should rotate. CamRotationSpeed = 27.0f ; // Rate at which the camera should rotate.
@ -145,7 +149,7 @@ namespace Execution
Model Topology ("./Models/topology.obj" ); Model Topology ("./Models/topology.obj" );
Model Torus ("./Models/Torus.obj" ); Model Torus ("./Models/Torus.obj" );
Material_Phong ObjectMaterial; Material_Phong ObjectMaterial; // Material to use on the model.
Light_Basic Light ; // Hardcoded light. Rotates around object. Light_Basic Light ; // Hardcoded light. Rotates around object.
Entity_Basic ObjectToView; // Object that will be currently in the middle with the light source rotating. Entity_Basic ObjectToView; // Object that will be currently in the middle with the light source rotating.
@ -163,6 +167,8 @@ namespace Execution
// Functionality // Functionality
// Input Action functions...
void ChangeModel() void ChangeModel()
{ {
if (CurrentModel == EModels::Torus) if (CurrentModel == EModels::Torus)
@ -191,6 +197,13 @@ namespace Execution
ObjectToView.SetPosition(Vector3(-0.05, -4.4f, 0)); 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; return;
} }
case EModels::Eight: case EModels::Eight:
@ -204,10 +217,17 @@ namespace Execution
ObjectToView.SetModel(Eight); ObjectToView.SetModel(Eight);
//ObjectToView.Scale(1.0f); ObjectToView.SetScale(2.0f);
ObjectToView.SetPosition(Vector3(0, -1.0, 0)); 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; return;
} }
case EModels::Gargoyle: case EModels::Gargoyle:
@ -225,6 +245,13 @@ namespace Execution
ObjectToView.SetScale(6.0f); 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; return;
} }
case EModels::Hand: case EModels::Hand:
@ -242,6 +269,43 @@ namespace Execution
ObjectToView.SetPosition(Vector3(0, -1.1f, 0)); 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; return;
} }
case EModels::Sculpture: case EModels::Sculpture:
@ -257,6 +321,15 @@ namespace Execution
ObjectToView.SetScale(0.01f); 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; return;
} }
case EModels::Topology: case EModels::Topology:
@ -272,6 +345,13 @@ namespace Execution
ObjectToView.SetScale(0.2f); 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; return;
} }
case EModels::Torus: case EModels::Torus:
@ -287,34 +367,39 @@ namespace Execution
ObjectToView.SetScale(1.0f); 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; return;
} }
} }
} }
auto ChangeModelDelegate = function<decltype(ChangeModel)>(ChangeModel);
void ToggleLight() void ToggleLight()
{ {
if (ShowLight) ShowLight ? ShowLight = false : ShowLight = true;
{
ShowLight = false;
return; return;
} }
else
void ToggleModelRotation()
{ {
ShowLight = true; RotateObj ? RotateObj = false : RotateObj = true;
return; return;
} }
void ToogleLightOrbit()
{
OrbitLight ? OrbitLight = false : OrbitLight = true;
return;
} }
auto ToogleLightDelegate = function<decltype(ToggleLight)>(ToggleLight);
// Input Action common functions...
void RotateCamera(ERotationAxis _rotationAxis, gFloat _rotationAmount, double _delta) void RotateCamera(ERotationAxis _rotationAxis, gFloat _rotationAmount, double _delta)
{ {
WorldCamera.Rotate(_rotationAxis, _rotationAmount, gFloat(_delta)); WorldCamera.Rotate(_rotationAxis, _rotationAmount, gFloat(_delta));
@ -322,9 +407,6 @@ namespace Execution
return; return;
} }
auto RotateCamDelegate = function<decltype(RotateCamera)>(RotateCamera);
void MoveCamera(EDirection _direction, gFloat _translationAmount, double _delta) void MoveCamera(EDirection _direction, gFloat _translationAmount, double _delta)
{ {
WorldCamera.Move(_direction, _translationAmount, gFloat(_delta)); WorldCamera.Move(_direction, _translationAmount, gFloat(_delta));
@ -332,10 +414,6 @@ namespace Execution
return; return;
} }
auto MoveCamDelegate = function<decltype(MoveCamera)>(MoveCamera);
// This is here cause its super repetitive..
void ModifyCamSpeed(bool _isPositive, double _delta) void ModifyCamSpeed(bool _isPositive, double _delta)
{ {
if (_isPositive) if (_isPositive)
@ -352,12 +430,9 @@ namespace Execution
} }
} }
auto ModifyCamSpeedDelegate = function<decltype(ModifyCamSpeed)>(ModifyCamSpeed);
auto SetPolyModeDelegate = function<decltype(SetPolygonMode)>(SetPolygonMode);
// End of common input functions... // End of common input functions...
void UpdateWindowDeltaTitle() void UpdateWindowDeltaTitle()
{ {
WindowTitle.str(""); WindowTitle.str("");
@ -371,7 +446,6 @@ namespace Execution
} }
// Currently Does everything required before entering the cycler. // Currently Does everything required before entering the cycler.
void PrepWorkspace() void PrepWorkspace()
{ {
@ -403,6 +477,7 @@ namespace Execution
// End of cursor stuff... // End of cursor stuff...
// Shaders // Shaders
LoadDefaultShaders(); LoadDefaultShaders();
@ -413,12 +488,16 @@ namespace Execution
Bunny.Load(); Bunny.Load();
ObjectMaterial.Color = DGL::Colors::WarmSphia.Vector(); ObjectMaterial.Color = DGL::Colors::White.Vector();
ObjectMaterial.Ambience = 0.112f ; ObjectMaterial.Ambience = 0.300f ;
ObjectMaterial.Diffuse = 0.928f ; ObjectMaterial.Diffuse = 1.000f ;
ObjectMaterial.Specular = 0.21f ; ObjectMaterial.Specular = 0.910f ;
ObjectToView = Entity_Basic(Bunny, ObjectMaterial); ObjectToView = Entity_Basic(Bunny, ObjectMaterial);
ObjectToView.SetScale(4.0f);
ObjectToView.SetPosition(Vector3(-0.05, -4.4f, 0));
} }
@ -470,8 +549,6 @@ namespace Execution
{ {
ClearBuffer(EFrameBuffer::Color, EFrameBuffer::Depth); ClearBuffer(EFrameBuffer::Color, EFrameBuffer::Depth);
SetClearColor(LinearColor(0.02f, 0.02f, 0.02f, 1.0f));
_renderProcedure(); _renderProcedure();
SwapBuffers(DefaultWindow); SwapBuffers(DefaultWindow);
@ -496,11 +573,30 @@ namespace Execution
return; 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) void InputProcedure(Window* _currentWindowContext)
{ {
static bool F1_Held = false, H_Held = false, M_Held = false; 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::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::H )) H_Held = false;
if (!KeyPressed(_currentWindowContext, EKeyCodes::M )) M_Held = false; if (!KeyPressed(_currentWindowContext, EKeyCodes::M )) M_Held = false;
@ -564,6 +660,20 @@ namespace Execution
ActionsToComplete.AddToQueue(SetPolyModeDelegate, DGL::EFace::Front_and_Back, DGL::ERenderMode::Fill); 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 (CursorOff)
{ {
if (CursorX != 0) if (CursorX != 0)
@ -636,7 +746,15 @@ namespace Execution
UpdateScreenspace(); UpdateScreenspace();
if (OrbitLight)
{
Light.Update(gFloat(PhysicsDelta)); Light.Update(gFloat(PhysicsDelta));
}
if (RotateObj)
{
ObjectToView.Rotate(-1.0f * gFloat(PhysicsDelta), EAxis::Y);
}
ObjectToView.Update(); ObjectToView.Update();