From f9c80fc3265fee4ba95903b2305fefbcfa6c2fb0 Mon Sep 17 00:00:00 2001 From: Ed94 Date: Thu, 27 Feb 2020 00:00:19 -0500 Subject: [PATCH] Missing tape and some extra polish. --- DGL/DGL_Entity.hpp | 73 ++++++++++---- DGL/DGL_Enum.hpp | 2 + DGL/DGL_Utilities.hpp | 2 +- Execution.cpp | 216 ++++++++++++++++++++++++++++++++---------- 4 files changed, 224 insertions(+), 69 deletions(-) diff --git a/DGL/DGL_Entity.hpp b/DGL/DGL_Entity.hpp index ed66cc3..ba24276 100644 --- a/DGL/DGL_Entity.hpp +++ b/DGL/DGL_Entity.hpp @@ -25,10 +25,14 @@ namespace DGL { namespace Colors { - LinearColor Coral (1.0f , 0.5f , 0.31f, 1.0f); - LinearColor Grey (0.60f, 0.60f, 0.60f, 1.0f); - LinearColor WarmSphia(0.54f, 0.52f, 0.5f , 1.0f); - LinearColor White (1.0f , 1.0f , 1.0f , 1.0f); + LinearColor Blue (0.3f , 0.3f , 0.6f , 1.0f); + LinearColor Coral (1.0f , 0.5f , 0.31f, 1.0f); + LinearColor DarkTone (0.21f , 0.21f, 0.21f, 1.0f); + LinearColor Green (0.10f , 0.60f, 0.20f, 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: Entity_Basic() : position (Vector3(0.0f) ), + rotation (Vector3(0.0f) ), scale (Vector3(1.0f) ), model (NULL ), transform(CoordSpace(1.0f)) @@ -212,6 +217,7 @@ namespace DGL Entity_Basic(Model& _model, Material_Phong& _material) : position (Vector3(0.0f) ), + rotation (Vector3(0.0f) ), scale (Vector3(1.0f) ), model (&_model ), transform(CoordSpace(1.0f)), @@ -219,6 +225,11 @@ namespace DGL //type (_type ) {}; + void SetMaterial(Material_Phong& _material) + { + material = _material; + } + void SetModel(Model& _model) { model = &_model; @@ -230,12 +241,6 @@ namespace DGL { scale = Vector3(_scaleBy); - transform = CoordSpace(1.0f); - - transform = Translate(transform, position); - - transform = Scale(transform, scale); - return; } @@ -243,18 +248,47 @@ namespace DGL { 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; } 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) @@ -283,10 +317,11 @@ namespace DGL // EEntityType type; - Vector3 position ; - Vector3 scale ; - Model* model ; - CoordSpace transform ; - Material_Phong material ; + Vector3 position ; + Vector3 rotation ; + Vector3 scale ; + Model* model ; + CoordSpace transform; + Material_Phong material ; }; } diff --git a/DGL/DGL_Enum.hpp b/DGL/DGL_Enum.hpp index 1a0f237..8ba2e52 100644 --- a/DGL/DGL_Enum.hpp +++ b/DGL/DGL_Enum.hpp @@ -127,6 +127,8 @@ namespace DGL F1 = GLFW_KEY_F1 , F2 = GLFW_KEY_F2 , F3 = GLFW_KEY_F3 , + F4 = GLFW_KEY_F4 , + F5 = GLFW_KEY_F5 , A = GLFW_KEY_A , D = GLFW_KEY_D , E = GLFW_KEY_E , diff --git a/DGL/DGL_Utilities.hpp b/DGL/DGL_Utilities.hpp index 3b151a1..c844af2 100644 --- a/DGL/DGL_Utilities.hpp +++ b/DGL/DGL_Utilities.hpp @@ -151,7 +151,7 @@ namespace DGL void InitalizeGLEW() { // If using GLEW version 1.13 or earlier - //glewExperimental = true; + glewExperimental = true; std::cout << "Initializing Glew Version: " << glewGetString(GLEW_VERSION) << std::endl; diff --git a/Execution.cpp b/Execution.cpp index 1ede4c8..e6c276b 100644 --- a/Execution.cpp +++ b/Execution.cpp @@ -31,6 +31,7 @@ namespace Execution { // DGL + using DGL::EAxis ; using DGL::EBool ; using DGL::ECursorMode ; using DGL::EDirection ; @@ -101,6 +102,7 @@ namespace Execution Eight , Gargoyle , Hand , + Horse , Sculpture, Topology , Torus @@ -111,19 +113,21 @@ namespace Execution 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 / 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. - RenderInterval = 1.0f / 144.0f ; // Interval per second to complete the render process of the cycle. + 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 ; + 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. @@ -145,7 +149,7 @@ namespace Execution Model Topology ("./Models/topology.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. Entity_Basic ObjectToView; // Object that will be currently in the middle with the light source rotating. @@ -163,6 +167,8 @@ namespace Execution // Functionality + // Input Action functions... + void ChangeModel() { if (CurrentModel == EModels::Torus) @@ -191,6 +197,13 @@ namespace Execution 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: @@ -204,10 +217,17 @@ namespace Execution ObjectToView.SetModel(Eight); - //ObjectToView.Scale(1.0f); + 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: @@ -225,6 +245,13 @@ namespace Execution 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: @@ -242,6 +269,43 @@ namespace Execution 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: @@ -257,6 +321,15 @@ namespace Execution 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: @@ -272,6 +345,13 @@ namespace Execution 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: @@ -287,33 +367,38 @@ namespace Execution 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; } } } - auto ChangeModelDelegate = function(ChangeModel); - - void ToggleLight() { - if (ShowLight) - { - ShowLight = false; + ShowLight ? ShowLight = false : ShowLight = true; - return; - } - else - { - ShowLight = true; - - return; - } + return; + } + + void ToggleModelRotation() + { + RotateObj ? RotateObj = false : RotateObj = true; + + return; + } + + void ToogleLightOrbit() + { + OrbitLight ? OrbitLight = false : OrbitLight = true; + + return; } - - auto ToogleLightDelegate = function(ToggleLight); - - // Input Action common functions... void RotateCamera(ERotationAxis _rotationAxis, gFloat _rotationAmount, double _delta) { @@ -322,9 +407,6 @@ namespace Execution return; } - auto RotateCamDelegate = function(RotateCamera); - - void MoveCamera(EDirection _direction, gFloat _translationAmount, double _delta) { WorldCamera.Move(_direction, _translationAmount, gFloat(_delta)); @@ -332,10 +414,6 @@ namespace Execution return; } - auto MoveCamDelegate = function(MoveCamera); - - - // This is here cause its super repetitive.. void ModifyCamSpeed(bool _isPositive, double _delta) { if (_isPositive) @@ -351,13 +429,10 @@ namespace Execution return; } } - - auto ModifyCamSpeedDelegate = function(ModifyCamSpeed); - auto SetPolyModeDelegate = function(SetPolygonMode); - - + // End of common input functions... + void UpdateWindowDeltaTitle() { WindowTitle.str(""); @@ -371,7 +446,6 @@ namespace Execution } - // Currently Does everything required before entering the cycler. void PrepWorkspace() { @@ -403,6 +477,7 @@ namespace Execution // End of cursor stuff... + // Shaders LoadDefaultShaders(); @@ -413,12 +488,16 @@ namespace Execution Bunny.Load(); - ObjectMaterial.Color = DGL::Colors::WarmSphia.Vector(); - ObjectMaterial.Ambience = 0.112f ; - ObjectMaterial.Diffuse = 0.928f ; - ObjectMaterial.Specular = 0.21f ; + 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)); } @@ -470,8 +549,6 @@ namespace Execution { ClearBuffer(EFrameBuffer::Color, EFrameBuffer::Depth); - SetClearColor(LinearColor(0.02f, 0.02f, 0.02f, 1.0f)); - _renderProcedure(); SwapBuffers(DefaultWindow); @@ -496,11 +573,30 @@ namespace Execution return; } + + + // Input functionality delegates (These are made due to a limitation with the actions implementation). + + auto ChangeModelDelegate = function(ChangeModel ); + auto ToogleLightDelegate = function(ToggleLight ); + auto ToggleModelRotationDelegate = function(ToggleModelRotation); + auto ToggleLightOrbitDelegate = function(ToogleLightOrbit ); + auto RotateCamDelegate = function(RotateCamera ); + auto MoveCamDelegate = function(MoveCamera ); + auto ModifyCamSpeedDelegate = function(ModifyCamSpeed ); + auto SetPolyModeDelegate = function(SetPolygonMode ); + 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::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; @@ -563,6 +659,20 @@ namespace Execution { 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) { @@ -636,7 +746,15 @@ namespace Execution UpdateScreenspace(); - Light.Update(gFloat(PhysicsDelta)); + if (OrbitLight) + { + Light.Update(gFloat(PhysicsDelta)); + } + + if (RotateObj) + { + ObjectToView.Rotate(-1.0f * gFloat(PhysicsDelta), EAxis::Y); + } ObjectToView.Update();