diff --git a/SHADE_Application/SHADE_Application.vcxproj b/SHADE_Application/SHADE_Application.vcxproj new file mode 100644 index 00000000..0a7457a0 --- /dev/null +++ b/SHADE_Application/SHADE_Application.vcxproj @@ -0,0 +1,132 @@ + + + + + Debug + x64 + + + Release + x64 + + + + {BDC70008-29DE-FE9D-7255-8ABFDEAACF25} + true + Win32Proj + SHADE_Application + 10.0 + + + + Application + true + Unicode + v142 + + + Application + false + Unicode + v142 + + + + + + + + + + + + + true + ..\bin\Debug\ + ..\bin_int\Debug\SHADE_Application\ + SHADE_Application + .exe + ..\Dependencies\spdlog\include;$(VULKAN_SDK)\include;..\Dependencies\VMA\include;$(VULKAN_SDK)\Source\SPIRV-Reflect;$(IncludePath) + + + false + ..\bin\Release\ + ..\bin_int\Release\SHADE_Application\ + SHADE_Application + .exe + ..\Dependencies\spdlog\include;$(VULKAN_SDK)\include;..\Dependencies\VMA\include;$(VULKAN_SDK)\Source\SPIRV-Reflect;$(IncludePath) + + + + Use + SBpch.h + Level4 + 4251;%(DisableSpecificWarnings) + NOMINMAX;_DEBUG;%(PreprocessorDefinitions) + ..\SHADE_Engine\src;src;..\Dependencies\dotnet\include;..\Dependencies\SDL\include;%(AdditionalIncludeDirectories) + EditAndContinue + Disabled + false + MultiThreadedDebugDLL + true + stdcpp20 + + + Windows + true + SDL2.lib;SDL2main.lib;%(AdditionalDependencies) + ..\Dependencies\spdlog\lib;..\Dependencies\SDL\lib;%(AdditionalLibraryDirectories) + wWinMainCRTStartup + + + + + Use + SBpch.h + Level4 + 4251;%(DisableSpecificWarnings) + NOMINMAX;_RELEASE;%(PreprocessorDefinitions) + ..\SHADE_Engine\src;src;..\Dependencies\dotnet\include;..\Dependencies\SDL\include;%(AdditionalIncludeDirectories) + Full + true + true + false + true + MultiThreadedDLL + true + stdcpp20 + + + Windows + true + true + SDL2.lib;SDL2main.lib;%(AdditionalDependencies) + ..\Dependencies\spdlog\lib;..\Dependencies\SDL\lib;%(AdditionalLibraryDirectories) + wWinMainCRTStartup + + + + + + + + + + + Create + + + + + + + {3F92E998-2BF5-783D-D47A-B1F3C0BC44C0} + + + {16DB1400-829B-9036-4BD6-D9B3B755D512} + + + + + + \ No newline at end of file diff --git a/SHADE_Application/src/Application/SBApplication.cpp b/SHADE_Application/src/Application/SBApplication.cpp index fa8a1888..847374d7 100644 --- a/SHADE_Application/src/Application/SBApplication.cpp +++ b/SHADE_Application/src/Application/SBApplication.cpp @@ -34,12 +34,12 @@ namespace Sandbox ( _In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, - _In_ LPWSTR lpCmdLine, + _In_ LPWSTR lpCmdLine, _In_ INT nCmdShow ) { - // Set working directory - SHADE::SHFileUtilities::SetWorkDirToExecDir(); + // Set working directory + SHADE::SHFileUtilities::SetWorkDirToExecDir(); SDL_Init(SDL_INIT_EVERYTHING); window.Create(hInstance, hPrevInstance, lpCmdLine, nCmdShow); diff --git a/SHADE_Engine/SHADE_Engine.vcxproj b/SHADE_Engine/SHADE_Engine.vcxproj new file mode 100644 index 00000000..37ddf8f5 --- /dev/null +++ b/SHADE_Engine/SHADE_Engine.vcxproj @@ -0,0 +1,349 @@ + + + + + Debug + x64 + + + Release + x64 + + + + {3F92E998-2BF5-783D-D47A-B1F3C0BC44C0} + true + Win32Proj + SHADE_Engine + 10.0 + + + + DynamicLibrary + true + Unicode + v142 + + + DynamicLibrary + false + Unicode + v142 + + + + + + + + + + + + + true + ..\bin\Debug\ + ..\bin_int\Debug\SHADE_Engine\ + SHADE_Engine + .dll + ..\Dependencies\assimp\include;..\Dependencies\imgui;..\Dependencies\imguizmo;..\Dependencies\imnodes;..\Dependencies\msdf;..\Dependencies\msdf\msdfgen;..\Dependencies\spdlog\include;..\Dependencies\tracy;..\Dependencies\VMA\include;..\Dependencies\yamlcpp\include;..\Dependencies\SDL\include;..\Dependencies\RTTR\include;..\Dependencies\reactphysics3d\include;$(VULKAN_SDK)\include;$(VULKAN_SDK)\Source\SPIRV-Reflect;..\Dependencies\dotnet\include;$(IncludePath) + + + false + ..\bin\Release\ + ..\bin_int\Release\SHADE_Engine\ + SHADE_Engine + .dll + ..\Dependencies\assimp\include;..\Dependencies\imgui;..\Dependencies\imguizmo;..\Dependencies\imnodes;..\Dependencies\msdf;..\Dependencies\msdf\msdfgen;..\Dependencies\spdlog\include;..\Dependencies\tracy;..\Dependencies\VMA\include;..\Dependencies\yamlcpp\include;..\Dependencies\SDL\include;..\Dependencies\RTTR\include;..\Dependencies\reactphysics3d\include;$(VULKAN_SDK)\include;$(VULKAN_SDK)\Source\SPIRV-Reflect;..\Dependencies\dotnet\include;$(IncludePath) + + + + Use + SHpch.h + Level4 + 4251;%(DisableSpecificWarnings) + _LIB;_GLFW_INCLUDE_NONE;MSDFGEN_USE_CPP11;NOMINMAX;SH_API_EXPORT;_DEBUG;%(PreprocessorDefinitions) + src;%(AdditionalIncludeDirectories) + EditAndContinue + Disabled + false + MultiThreadedDebugDLL + true + stdcpp20 + + + Windows + true + vulkan-1.lib;SDL2.lib;SDL2main.lib;shaderc_shared.lib;shlwapi.lib;assimp-vc142-mtd.lib;librttr_core_d.lib;spdlogd.lib;%(AdditionalDependencies) + libs;$(VULKAN_SDK)\Lib;..\Dependencies\assimp\lib\Debug;..\Dependencies\assimp\lib\Release;..\Dependencies\RTTR\lib;..\Dependencies\SDL\lib;..\Dependencies\spdlog\lib;%(AdditionalLibraryDirectories) + ..\bin\Debug\SHADE_Engine.lib + + + xcopy /s /r /y /q "$(SolutionDir)/Dependencies/spdlog/bin" "$(OutDir)" +xcopy /r /y /q "$(SolutionDir)/Dependencies/SDL/lib/SDL2.dll" "$(OutDir)" +xcopy /s /r /y /q "$(SolutionDir)/Dependencies/dotnet/bin" "$(OutDir)" + + + + + Use + SHpch.h + Level4 + 4251;%(DisableSpecificWarnings) + _LIB;_GLFW_INCLUDE_NONE;MSDFGEN_USE_CPP11;NOMINMAX;SH_API_EXPORT;_RELEASE;%(PreprocessorDefinitions) + src;%(AdditionalIncludeDirectories) + Full + true + true + false + true + MultiThreadedDLL + true + stdcpp20 + + + Windows + true + true + vulkan-1.lib;SDL2.lib;SDL2main.lib;shaderc_shared.lib;shlwapi.lib;assimp-vc142-mt.lib;librttr_core.lib;spdlog.lib;%(AdditionalDependencies) + libs;$(VULKAN_SDK)\Lib;..\Dependencies\assimp\lib\Debug;..\Dependencies\assimp\lib\Release;..\Dependencies\RTTR\lib;..\Dependencies\SDL\lib;..\Dependencies\spdlog\lib;%(AdditionalLibraryDirectories) + ..\bin\Release\SHADE_Engine.lib + + + xcopy /s /r /y /q "$(SolutionDir)/Dependencies/spdlog/bin" "$(OutDir)" +xcopy /r /y /q "$(SolutionDir)/Dependencies/SDL/lib/SDL2.dll" "$(OutDir)" +xcopy /s /r /y /q "$(SolutionDir)/Dependencies/dotnet/bin" "$(OutDir)" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Create + + + + + + + + + + + + + + {88F1A057-74BE-FB62-9DD7-E90A890331F1} + + + {8900D8DD-F5DF-5679-FEF7-E14F6A56BDDA} + + + {38BD587B-248B-4C81-0D1F-BDA7F98B28E6} + + + {2ECAB41A-1A98-A820-032C-1947EF988485} + + + {C0FF640D-2C14-8DBE-F595-301E616989EF} + + + + + + \ No newline at end of file diff --git a/SHADE_Engine/SHADE_Engine.vcxproj.filters b/SHADE_Engine/SHADE_Engine.vcxproj.filters new file mode 100644 index 00000000..f52aebb0 --- /dev/null +++ b/SHADE_Engine/SHADE_Engine.vcxproj.filters @@ -0,0 +1,746 @@ + + + + + {8EEA3EAC-7A8C-6982-6347-7DD64F88F0D2} + + + {1AB26817-067F-C322-2F98-B1CA1BC4F8B0} + + + {EFD23933-5B34-1741-E4A1-5DF350024E00} + + + {261D0942-92A8-7606-9BB9-F9FA07C4D206} + + + {BEBC9142-2A48-FF06-3359-82FB9F635B07} + + + {07FEB307-F3F6-D259-1C29-B8DE0881B265} + + + {37718753-A387-85E9-ECFE-100B58545671} + + + {EE037863-5A8F-E527-63A0-681CCFAA4128} + + + {078AA1A3-F318-2B6D-9C37-3F6888A53B13} + + + {DBC7D3B0-C769-FE86-B024-12DB9C6585D7} + + + {3A8963B1-262B-8E87-0FE6-A1DBFB2615D8} + + + {80E7870B-ECF0-877C-756C-9E7CE174937C} + + + {8A8E2B37-7646-6D84-DF4D-46E0CB240875} + + + {1653CE33-0220-293F-2B39-17E717655ECD} + + + {92C817CE-7EC1-3620-A7F3-1BA5934B162C} + + + {17C745C0-83DD-4356-CC54-CF7738AA14DE} + + + {51443AC7-3D28-FB1C-A688-F56F928BE59E} + + + {573A6CF2-43C9-F5BB-ECE7-09B7D8550662} + + + {08DBDC43-F4D3-FB95-1D06-E11A095EDBA1} + + + {4AD5CA42-3664-540C-DF82-6807CBF064B2} + + + {FB5EE099-67EA-4D5E-70FB-D052DC05AA5E} + + + {BA26540B-263D-52A1-6FB4-DDC2DB092329} + + + {4B204703-3704-0859-A064-02AC8C67F2DA} + + + {EBA1D3FF-D75C-C3AB-8014-3CF66CAE0D3C} + + + {8CDBA7C9-F8E8-D5AF-81CF-D19AEDDBA166} + + + {2460C057-1070-6C28-7929-D14665585BC1} + + + {FBD334F8-67EA-328E-B061-BEAF1CB70316} + + + {1DD51CAD-8960-8A71-9271-0D66FE7BE671} + + + {57DAB30C-4369-3DD6-EC87-51D1D8F54D7C} + + + {9C0DAFD9-086F-8CE7-91DC-D299FD3CC3A6} + + + {EF2D07CC-DB26-261E-0459-0BA3F0B0052A} + + + {3AEF06DD-A6D2-151D-AFD5-43591B38DC6D} + + + {245F5AB0-1085-2417-F9CA-A9E2E58F49E3} + + + {03DB39DE-EFBE-FA33-581F-F5864422E5B5} + + + {576DF841-4392-47C2-6CDD-2C52586146E0} + + + {75F29FE5-6102-4CB6-CABB-B0D4B6EA3A4F} + + + {5BAB2A92-478F-EBE7-B0EF-E53A9CF2D569} + + + {B3B14D12-9FC1-F9E2-087B-5E01F4A9E87B} + + + {AFF4887C-9B2B-8A0D-4418-7010302E060F} + + + {EAD6C33D-5697-3F74-1FD2-88F18B518450} + + + {F1B75745-5D6D-D03A-E661-CA115216C73E} + + + {AC05897C-983C-8A0D-4129-70102D3F060F} + + + {ED6CDF9B-D939-3AA7-0253-284FEE7E6F35} + + + {B3F7140E-1F0C-3DBF-E88D-E01E546139F0} + + + {985A7358-04C5-27CF-4D03-D974B9AC0524} + + + {16CF2D0E-82E3-55BF-4B65-F91EB73852F0} + + + + + Common + + + ECS_Base\Components + + + ECS_Base\Components + + + ECS_Base\Entity + + + ECS_Base\Events + + + ECS_Base\Events + + + ECS_Base\General + + + ECS_Base\General + + + ECS_Base\General + + + ECS_Base\General + + + ECS_Base\General + + + ECS_Base\Managers + + + ECS_Base\Managers + + + ECS_Base\Managers + + + ECS_Base + + + ECS_Base\System + + + ECS_Base\System + + + ECS_Base\System + + + ECS_Base\System + + + ECS_Base\UnitTesting + + + ECS_Base\UnitTesting + + + ECS_Base\UnitTesting + + + Engine + + + Events + + + Events + + + Events + + + Events + + + FRC + + + Filesystem + + + Graphics\Buffers + + + Graphics\Commands + + + Graphics\Commands + + + Graphics\Commands + + + Graphics\Debugging + + + Graphics\Debugging + + + Graphics\Debugging + + + Graphics\Descriptors + + + Graphics\Descriptors + + + Graphics\Descriptors + + + Graphics\Descriptors + + + Graphics\Descriptors + + + Graphics\Descriptors + + + Graphics\Devices + + + Graphics\Devices + + + Graphics\Devices + + + Graphics\Framebuffer + + + Graphics\Images + + + Graphics\Images + + + Graphics\Images + + + Graphics\Images + + + Graphics\Instance + + + Graphics\MiddleEnd\Interface + + + Graphics\MiddleEnd\Interface + + + Graphics\MiddleEnd\PerFrame + + + Graphics\MiddleEnd\PerFrame + + + Graphics\MiddleEnd\Shaders + + + Graphics\MiddleEnd\Shaders + + + Graphics\MiddleEnd\Shaders + + + Graphics\Pipeline + + + Graphics\Pipeline + + + Graphics\Pipeline + + + Graphics\Pipeline + + + Graphics\Pipeline + + + Graphics\Pipeline + + + Graphics\Queues + + + Graphics\RenderGraph + + + Graphics\Renderpass + + + Graphics\Renderpass + + + Graphics\Renderpass + + + Graphics\Renderpass + + + Graphics\Renderpass + + + Graphics + + + Graphics + + + Graphics + + + Graphics\Shaders\BlockInterface + + + Graphics\Shaders + + + Graphics\Shaders + + + Graphics\Shaders\spirv-reflect + + + Graphics\Swapchain + + + Graphics\Swapchain + + + Graphics\Synchronization + + + Graphics\Synchronization + + + Graphics\VertexDescriptors + + + Graphics\Windowing + + + Graphics\Windowing + + + Graphics\Windowing\Surface + + + Math\Geometry + + + Math\Geometry + + + Math + + + Math + + + Math + + + Math + + + Math + + + Math + + + Math\Vector + + + Math\Vector + + + Math\Vector + + + Meta + + + Resource + + + Resource + + + Resource + + + Resource + + + Resource + + + Resource + + + + + + Scene + + + Scene + + + Scene + + + Scripting + + + Scripting + + + Scripting + + + Tools + + + Tools + + + Tools + + + Tools + + + Tools + + + Tools + + + Tools + + + Tools + + + + + + + ECS_Base\Components + + + ECS_Base\Components + + + ECS_Base\Entity + + + ECS_Base\Managers + + + ECS_Base\Managers + + + ECS_Base\Managers + + + ECS_Base\System + + + ECS_Base\System + + + ECS_Base\UnitTesting + + + Engine + + + FRC + + + Filesystem + + + Graphics\Buffers + + + Graphics\Commands + + + Graphics\Commands + + + Graphics\Debugging + + + Graphics\Debugging + + + Graphics\Debugging + + + Graphics\Descriptors + + + Graphics\Descriptors + + + Graphics\Descriptors + + + Graphics\Descriptors + + + Graphics\Descriptors + + + Graphics\Descriptors + + + Graphics\Devices + + + Graphics\Devices + + + Graphics\Devices + + + Graphics\Framebuffer + + + Graphics\Images + + + Graphics\Images + + + Graphics\Images + + + Graphics\Instance + + + Graphics\MiddleEnd\Interface + + + Graphics\MiddleEnd\Interface + + + Graphics\MiddleEnd\PerFrame + + + Graphics\MiddleEnd\PerFrame + + + Graphics\MiddleEnd\Shaders + + + Graphics\MiddleEnd\Shaders + + + Graphics\Pipeline + + + Graphics\Pipeline + + + Graphics\Pipeline + + + Graphics\Pipeline + + + Graphics\Queues + + + Graphics\RenderGraph + + + Graphics\Renderpass + + + Graphics\Renderpass + + + Graphics\Renderpass + + + Graphics + + + Graphics + + + Graphics\Shaders\BlockInterface + + + Graphics\Shaders + + + Graphics\Shaders + + + Graphics\Shaders\spirv-reflect + + + Graphics\Swapchain + + + Graphics\Synchronization + + + Graphics\Synchronization + + + Graphics\VertexDescriptors + + + Graphics\Windowing + + + Graphics\Windowing + + + Graphics\Windowing\Surface + + + Math\Geometry + + + Math\Geometry + + + Math + + + Math + + + Math + + + Math + + + Math\Vector + + + Math\Vector + + + Math\Vector + + + Resource + + + + Scene + + + Scene + + + Scripting + + + Scripting + + + Tools + + + Tools + + + Tools + + + Tools + + + Tools + + + + + \ No newline at end of file diff --git a/SHADE_Engine/src/ECS_Base/Managers/SHComponentManager.h b/SHADE_Engine/src/ECS_Base/Managers/SHComponentManager.h index 20720760..60625d6a 100644 --- a/SHADE_Engine/src/ECS_Base/Managers/SHComponentManager.h +++ b/SHADE_Engine/src/ECS_Base/Managers/SHComponentManager.h @@ -36,7 +36,7 @@ namespace SHADE //The Container of all Componentgroups static std::vector componentGroups; - friend struct SHSceneNode; + friend class SHSceneNode; diff --git a/SHADE_Engine/src/Math/Geometry/SHBoundingBox.cpp b/SHADE_Engine/src/Math/Geometry/SHBoundingBox.cpp new file mode 100644 index 00000000..44f01a4b --- /dev/null +++ b/SHADE_Engine/src/Math/Geometry/SHBoundingBox.cpp @@ -0,0 +1,267 @@ +/**************************************************************************************** + * \file SHBoundingBox.cpp + * \author Diren D Bharwani, diren.dbharwani, 390002520 + * \brief Implementation for a 3-Dimensional Axis Aligned Bounding Box + * + * \copyright Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or + * disclosure of this file or its contents without the prior written consent + * of DigiPen Institute of Technology is prohibited. +****************************************************************************************/ + +#include + +// Primary Header +#include "SHBoundingBox.h" +// Project Headers +#include "Math/SHMathHelpers.h" + +namespace SHADE +{ + /*-----------------------------------------------------------------------------------*/ + /* Constructors & Destructor Definitions */ + /*-----------------------------------------------------------------------------------*/ + + SHBoundingBox::SHBoundingBox(const SHVec3& c, SHVec3& hE) noexcept + : SHShape {} + , center { c } + , halfExtents { hE } + { + type = Type::BOUNDING_BOX; + } + + SHBoundingBox::SHBoundingBox(const SHVec3* vertices, size_t numVertices) noexcept + : SHShape {} + { + type = Type::BOUNDING_BOX; + + if (vertices == nullptr || numVertices < 2) + { + SHLOG_ERROR("Insufficient number of vertices passed into bounding box constructor!") + return; + } + + SHVec3 min { std::numeric_limits::max() }; + SHVec3 max { std::numeric_limits::min() }; + + for (size_t i = 0; i < numVertices; ++i) + { + const SHVec3& v = vertices[i]; + + min.x = SHMath::Min(min.x, v.x); + min.y = SHMath::Min(min.y, v.y); + min.z = SHMath::Min(min.z, v.z); + + max.x = SHMath::Max(max.x, v.x); + max.y = SHMath::Max(max.y, v.y); + max.z = SHMath::Max(max.z, v.z); + } + + center = SHVec3::Lerp(min, max, 0.5f); + halfExtents = SHVec3::Abs((max - min) * 0.5f); + } + + SHBoundingBox::SHBoundingBox(const SHBoundingBox* boxes, size_t numBoxes) noexcept + : SHShape {} + { + type = Type::BOUNDING_BOX; + + if (boxes == nullptr || numBoxes == 0) + { + SHLOG_ERROR("Insufficient number of boxes passed into bounding box constructor!") + return; + } + + center = boxes->center; + halfExtents = boxes->halfExtents; + + for (size_t i = 1; i < numBoxes; ++i) + *this = Combine(*this, boxes[i]); + } + + SHBoundingBox::SHBoundingBox(const SHBoundingBox& rhs) noexcept + : SHShape {} + , center { rhs.center } + , halfExtents { rhs.halfExtents } + { + type = Type::BOUNDING_BOX; + } + + SHBoundingBox::SHBoundingBox(SHBoundingBox&& rhs) noexcept + : SHShape {} + , center { rhs.center } + , halfExtents { rhs.halfExtents } + { + type = Type::BOUNDING_BOX; + } + + SHBoundingBox& SHBoundingBox::operator=(const SHBoundingBox& rhs) noexcept + { + if (rhs.type != Type::BOUNDING_BOX) + { + SHLOG_WARNING("Cannot assign a non-bounding box to a bounding box!") + } + else + { + center = rhs.center; + halfExtents = rhs.halfExtents; + } + + return *this; + } + + SHBoundingBox& SHBoundingBox::operator=(SHBoundingBox&& rhs) noexcept + { + if (rhs.type != Type::BOUNDING_BOX) + { + SHLOG_WARNING("Cannot assign a non-bounding box to a bounding box!") + } + else + { + center = rhs.center; + halfExtents = rhs.halfExtents; + } + + return *this; + } + + /*-----------------------------------------------------------------------------------*/ + /* Getter Function Definitions */ + /*-----------------------------------------------------------------------------------*/ + + const SHVec3& SHBoundingBox::GetCenter() const noexcept + { + return center; + } + + const SHVec3& SHBoundingBox::GetHalfExtents() const noexcept + { + return halfExtents; + } + + SHVec3 SHBoundingBox::GetMin() const noexcept + { + return center - halfExtents; + } + + SHVec3 SHBoundingBox::GetMax() const noexcept + { + return center + halfExtents; + } + + /*-----------------------------------------------------------------------------------*/ + /* Setter Function Definitions */ + /*-----------------------------------------------------------------------------------*/ + + void SHBoundingBox::SetCenter(const SHVec3& newCenter) noexcept + { + center = newCenter; + } + + void SHBoundingBox::SetHalfExtents(const SHVec3& newHalfExtents) noexcept + { + halfExtents = newHalfExtents; + } + + void SHBoundingBox::SetMin(const SHVec3& min) noexcept + { + const SHVec3 MAX = center + halfExtents; + + center = SHVec3::Lerp(min, MAX, 0.5f); + halfExtents = SHVec3::Abs((MAX - min) * 0.5f); + } + + void SHBoundingBox::SetMax(const SHVec3& max) noexcept + { + const SHVec3 MIN = center - halfExtents; + + center = SHVec3::Lerp(MIN, max, 0.5f); + halfExtents = SHVec3::Abs((max - MIN) * 0.5f); + } + + void SHBoundingBox::SetMinMax(const SHVec3& min, const SHVec3& max) noexcept + { + center = SHVec3::Lerp(min, max, 0.5f); + halfExtents = SHVec3::Abs((max - min) * 0.5f); + } + + + /*-----------------------------------------------------------------------------------*/ + /* Public Function Member Definitions */ + /*-----------------------------------------------------------------------------------*/ + + bool SHBoundingBox::TestPoint(const SHVec3& point) noexcept + { + const SHVec3 V = SHVec3::Abs(point - center); + for (size_t i = 0; i < SHVec3::SIZE; ++i) + { + if (V[i] > halfExtents[i]) + return false; + } + + return true; + } + + bool SHBoundingBox::Contains(const SHBoundingBox& rhs) const noexcept + { + const SHVec3 V = SHVec3::Abs(rhs.center - center); + for (size_t i = 0; i < SHVec3::SIZE; ++i) + { + if (V[i] > rhs.halfExtents[i]) + return false; + } + + return true; + } + + float SHBoundingBox::Volume() const noexcept + { + return 8.0f * (halfExtents.x * halfExtents.y * halfExtents.z); + } + + float SHBoundingBox::SurfaceArea() const noexcept + { + return 8.0f * ((halfExtents.x * halfExtents.y) + + (halfExtents.x * halfExtents.z) + + (halfExtents.y * halfExtents.z)); + } + + /*-----------------------------------------------------------------------------------*/ + /* Static Function Member Definitions */ + /*-----------------------------------------------------------------------------------*/ + + SHBoundingBox SHBoundingBox::Combine(const SHBoundingBox& lhs, const SHBoundingBox& rhs) noexcept + { + if (lhs.Contains(rhs)) + return lhs; + + if (rhs.Contains(lhs)) + return rhs; + + const SHVec3 LHS_MIN = lhs.GetMin(); + const SHVec3 LHS_MAX = lhs.GetMax(); + const SHVec3 RHS_MIN = rhs.GetMin(); + const SHVec3 RHS_MAX = rhs.GetMax(); + + SHVec3 min = SHVec3::Min({ LHS_MIN, RHS_MIN }); + SHVec3 max = SHVec3::Max({ LHS_MAX, RHS_MAX }); + + SHBoundingBox result{ lhs }; + result.SetMinMax(min, max); + return result; + } + + bool SHBoundingBox::Intersect(const SHBoundingBox& lhs, const SHBoundingBox& rhs) noexcept + { + const SHVec3 V = SHVec3::Abs(lhs.center - rhs.center); + const SHVec3 D = lhs.halfExtents + rhs.halfExtents; + + for (size_t i = 0; i < SHVec3::SIZE; ++i) + { + if (V[i] > D[i]) + return false; + } + + return true; + } + +} // namespace SHADE \ No newline at end of file diff --git a/SHADE_Engine/src/Math/Geometry/SHBoundingBox.h b/SHADE_Engine/src/Math/Geometry/SHBoundingBox.h new file mode 100644 index 00000000..b60c6c29 --- /dev/null +++ b/SHADE_Engine/src/Math/Geometry/SHBoundingBox.h @@ -0,0 +1,88 @@ +/**************************************************************************************** + * \file SHBoundingBox.h + * \author Diren D Bharwani, diren.dbharwani, 390002520 + * \brief Interface for a 3-Dimensional Axis Aligned Bounding Box + * + * \copyright Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or + * disclosure of this file or its contents without the prior written consent + * of DigiPen Institute of Technology is prohibited. +****************************************************************************************/ + +#pragma once + +// Project Headers +#include "SHShape.h" +#include "SH_API.h" + +namespace SHADE +{ + /*-----------------------------------------------------------------------------------*/ + /* Type Definitions */ + /*-----------------------------------------------------------------------------------*/ + + class SH_API SHBoundingBox : public SHShape + { + public: + /*---------------------------------------------------------------------------------*/ + /* Constructors & Destructor */ + /*---------------------------------------------------------------------------------*/ + + SHBoundingBox (const SHVec3& center, SHVec3& halfExtents) noexcept; + SHBoundingBox (const SHVec3* vertices, size_t numVertices) noexcept; + SHBoundingBox (const SHBoundingBox* boxes, size_t numBoxes) noexcept; + + SHBoundingBox (const SHBoundingBox& rhs) noexcept; + SHBoundingBox (SHBoundingBox&& rhs) noexcept; + + SHBoundingBox& operator= (const SHBoundingBox& rhs) noexcept; + SHBoundingBox& operator= (SHBoundingBox&& rhs) noexcept; + + /*---------------------------------------------------------------------------------*/ + /* Getter Functions */ + /*---------------------------------------------------------------------------------*/ + + [[nodiscard]] const SHVec3& GetCenter () const noexcept; + [[nodiscard]] const SHVec3& GetHalfExtents () const noexcept; + [[nodiscard]] SHVec3 GetMin () const noexcept; + [[nodiscard]] SHVec3 GetMax () const noexcept; + + /*---------------------------------------------------------------------------------*/ + /* Setter Functions */ + /*---------------------------------------------------------------------------------*/ + + void SetCenter (const SHVec3& newCenter) noexcept; + void SetHalfExtents (const SHVec3& newHalfExtents) noexcept; + void SetMin (const SHVec3& min) noexcept; + void SetMax (const SHVec3& max) noexcept; + void SetMinMax (const SHVec3& min, const SHVec3& max) noexcept; + + + /*---------------------------------------------------------------------------------*/ + /* Function Members */ + /*---------------------------------------------------------------------------------*/ + + [[nodiscard]] bool TestPoint (const SHVec3& point) noexcept override; + + [[nodiscard]] bool Contains (const SHBoundingBox& rhs) const noexcept; + [[nodiscard]] float Volume () const noexcept; + [[nodiscard]] float SurfaceArea () const noexcept; + + /*---------------------------------------------------------------------------------*/ + /* Static Function Members */ + /*---------------------------------------------------------------------------------*/ + + [[nodiscard]] static SHBoundingBox Combine (const SHBoundingBox& lhs, const SHBoundingBox& rhs) noexcept; + [[nodiscard]] static bool Intersect (const SHBoundingBox& lhs, const SHBoundingBox& rhs) noexcept; + + private: + /*---------------------------------------------------------------------------------*/ + /* Data Members */ + /*---------------------------------------------------------------------------------*/ + + SHVec3 center; + SHVec3 halfExtents; + }; + + +} // namespace SHADE + diff --git a/SHADE_Engine/src/Math/Geometry/SHShape.cpp b/SHADE_Engine/src/Math/Geometry/SHShape.cpp new file mode 100644 index 00000000..02aaff58 --- /dev/null +++ b/SHADE_Engine/src/Math/Geometry/SHShape.cpp @@ -0,0 +1,26 @@ +/**************************************************************************************** + * \file SHShape.cpp + * \author Diren D Bharwani, diren.dbharwani, 390002520 + * \brief Implementation for a shape. + * + * \copyright Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or + * disclosure of this file or its contents without the prior written consent + * of DigiPen Institute of Technology is prohibited. +****************************************************************************************/ + +#include + +// Primary Header +#include "SHShape.h" + +namespace SHADE +{ + /*-----------------------------------------------------------------------------------*/ + /* Constructors & Destructor Definitions */ + /*-----------------------------------------------------------------------------------*/ + + SHShape::SHShape() + : type { Type::NONE } + {} + +} // namespace SHADE \ No newline at end of file diff --git a/SHADE_Engine/src/Math/Geometry/SHShape.h b/SHADE_Engine/src/Math/Geometry/SHShape.h new file mode 100644 index 00000000..84b7bbe7 --- /dev/null +++ b/SHADE_Engine/src/Math/Geometry/SHShape.h @@ -0,0 +1,79 @@ +/**************************************************************************************** + * \file SHShape.h + * \author Diren D Bharwani, diren.dbharwani, 390002520 + * \brief Interface for a shape. + * + * \copyright Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or + * disclosure of this file or its contents without the prior written consent + * of DigiPen Institute of Technology is prohibited. +****************************************************************************************/ + +#pragma once + +// Project Headers +#include "Math/Transform/SHTransform.h" +#include "SH_API.h" + +namespace SHADE +{ + /*-----------------------------------------------------------------------------------*/ + /* Type Definitions */ + /*-----------------------------------------------------------------------------------*/ + + class SH_API SHShape + { + public: + /*---------------------------------------------------------------------------------*/ + /* Type Definitions */ + /*---------------------------------------------------------------------------------*/ + + enum class Type + { + BOUNDING_BOX + , RAY + , TRIANGLE + + , COUNT + , NONE = -1 + }; + + /*---------------------------------------------------------------------------------*/ + /* Data Members */ + /*---------------------------------------------------------------------------------*/ + + bool isIntersecting; + + /*---------------------------------------------------------------------------------*/ + /* Constructors & Destructor */ + /*---------------------------------------------------------------------------------*/ + + virtual ~SHShape () = default; + + SHShape (const SHShape&) = default; + SHShape (SHShape&&) = default; + + SHShape& operator=(const SHShape&) = default; + SHShape& operator=(SHShape&&) = default; + + SHShape(); + + /*---------------------------------------------------------------------------------*/ + /* Getter Functions */ + /*---------------------------------------------------------------------------------*/ + + [[nodiscard]] Type GetType() const; + + /*---------------------------------------------------------------------------------*/ + /* Function Members */ + /*---------------------------------------------------------------------------------*/ + + [[nodiscard]] virtual bool TestPoint (const SHVec3& point) noexcept = 0; + + protected: + /*---------------------------------------------------------------------------------*/ + /* Data Members */ + /*---------------------------------------------------------------------------------*/ + + Type type; + }; +} // namespace SHADE \ No newline at end of file diff --git a/SHADE_Engine/src/Math/SHMath.h b/SHADE_Engine/src/Math/SHMath.h index 9763abe2..55bf73a9 100644 --- a/SHADE_Engine/src/Math/SHMath.h +++ b/SHADE_Engine/src/Math/SHMath.h @@ -6,4 +6,7 @@ #include "Vector/SHVec3.h" #include "Vector/SHVec4.h" -#include "SHMatrix.h" \ No newline at end of file +#include "SHQuaternion.h" +#include "SHMatrix.h" + +#include "SHTransform.h" \ No newline at end of file diff --git a/SHADE_Engine/src/Math/SHMathHelpers.h b/SHADE_Engine/src/Math/SHMathHelpers.h index 9135230e..427011a6 100644 --- a/SHADE_Engine/src/Math/SHMathHelpers.h +++ b/SHADE_Engine/src/Math/SHMathHelpers.h @@ -15,6 +15,9 @@ #include #include +// Project Headers +#include "SH_API.h" + namespace SHADE { @@ -35,7 +38,7 @@ namespace SHADE /* Type Definitions */ /*-----------------------------------------------------------------------------------*/ - class SHMath + class SH_API SHMath { public: /*---------------------------------------------------------------------------------*/ @@ -56,25 +59,37 @@ namespace SHADE /* Static Function Members */ /*---------------------------------------------------------------------------------*/ - static void Initialise (); + static void Initialise (); template - [[nodiscard]] static constexpr T DegreesToRadians (T angleInDeg); + [[nodiscard]] static T Min (T lhs, T rhs); template - [[nodiscard]] static constexpr T RadiansToDegrees (T angleInRad); + [[nodiscard]] static T Min (const std::initializer_list& values); template - [[nodiscard]] static T Lerp (T a, T b, T alpha); + [[nodiscard]] static T Max (T lhs, T rhs); template - [[nodiscard]] static T ClampedLerp (T a, T b, T alpha, T alphaMin, T alphaMax); + [[nodiscard]] static T Max (const std::initializer_list& values); template - [[nodiscard]] static T Wrap (T value, T min, T max); + [[nodiscard]] static T DegreesToRadians (T angleInDeg); + + template + [[nodiscard]] static T RadiansToDegrees (T angleInRad); + + template + [[nodiscard]] static T Lerp (T a, T b, T alpha); + + template + [[nodiscard]] static T ClampedLerp (T a, T b, T alpha, T alphaMin, T alphaMax); + + template + [[nodiscard]] static T Wrap (T value, T min, T max); template - [[nodiscard]] static T GenerateRandomNumber (T lowerBound = 0, T upperBound = 1); + [[nodiscard]] static T GenerateRandomNumber (T lowerBound = 0, T upperBound = 1); /** * @brief Compares two floating-point values for equality within given tolerances. @@ -86,7 +101,7 @@ namespace SHADE * @returns True if the values are equal within the specified tolerances. */ template - [[nodiscard]] static bool CompareFloat (T lhs, T rhs, T absTolerance = EPSILON, T relTolerance = EPSILON); + [[nodiscard]] static bool CompareFloat (T lhs, T rhs, T absTolerance = EPSILON, T relTolerance = EPSILON); private: /*---------------------------------------------------------------------------------*/ diff --git a/SHADE_Engine/src/Math/SHMathHelpers.hpp b/SHADE_Engine/src/Math/SHMathHelpers.hpp index f0a1de12..0e5fc5fa 100644 --- a/SHADE_Engine/src/Math/SHMathHelpers.hpp +++ b/SHADE_Engine/src/Math/SHMathHelpers.hpp @@ -13,11 +13,8 @@ // Primary Header #include "SHMathHelpers.h" -#include #include -// TODOs (Diren): Include pch? - namespace SHADE { /*-----------------------------------------------------------------------------------*/ @@ -25,13 +22,51 @@ namespace SHADE /*-----------------------------------------------------------------------------------*/ template - constexpr T SHMath::DegreesToRadians(T angleInDeg) + T SHMath::Min(T lhs, T rhs) + { + return lhs < rhs ? lhs : rhs; + } + + template + T SHMath::Min(const std::initializer_list& values) + { + T min = *(values.begin()); + + for (auto value : values) + { + min = Min(min, value); + } + + return min; + } + + template + T SHMath::Max(T lhs, T rhs) + { + return lhs > rhs ? lhs : rhs; + } + + template + T SHMath::Max(const std::initializer_list& values) + { + T max = *(values.begin()); + + for (auto value : values) + { + max = Min(max, value); + } + + return max; + } + + template + T SHMath::DegreesToRadians(T angleInDeg) { return angleInDeg * static_cast(PI / 180.0f); } template - constexpr T SHMath::RadiansToDegrees(T angleInRad) + T SHMath::RadiansToDegrees(T angleInRad) { return angleInRad * static_cast(180.0f / PI); } @@ -82,9 +117,10 @@ namespace SHADE template - bool CompareFloat(T lhs, T rhs, T absTolerance, T relTolerance) + bool SHMath::CompareFloat(T lhs, T rhs, T absTolerance, T relTolerance) { - return std::fabs(lhs - rhs) <= std::max(absTolerance, relTolerance * std::max(abs(lhs), abs(rhs))); + const T RTOL = relTolerance * Max(std::fabs(lhs), std::fabs(rhs)); + return std::fabs(lhs - rhs) <= MAX(absTolerance, RTOL); } } // namespace SHADE \ No newline at end of file diff --git a/SHADE_Engine/src/Math/SHMatrix.cpp b/SHADE_Engine/src/Math/SHMatrix.cpp index 8e8281d0..94c17914 100644 --- a/SHADE_Engine/src/Math/SHMatrix.cpp +++ b/SHADE_Engine/src/Math/SHMatrix.cpp @@ -362,7 +362,6 @@ namespace SHADE SHMatrix result; XMStoreFloat4x4(&result, XMMatrixTranslation(x, y, z)); - result.Transpose(); return result; } @@ -371,7 +370,6 @@ namespace SHADE SHMatrix result; XMStoreFloat4x4(&result, XMMatrixTranslation(pos.x, pos.y, pos.z)); - result.Transpose(); return result; } @@ -382,7 +380,6 @@ namespace SHADE const XMVECTOR A = XMLoadFloat3(&axis); XMStoreFloat4x4(&result, XMMatrixRotationAxis(A, angleInRad)); - result.Transpose(); return result; } @@ -391,7 +388,6 @@ namespace SHADE SHMatrix result; XMStoreFloat4x4(&result, XMMatrixRotationRollPitchYaw(pitch, yaw, roll)); - result.Transpose(); return result; } @@ -400,7 +396,6 @@ namespace SHADE SHMatrix result; XMStoreFloat4x4(&result, XMMatrixRotationRollPitchYaw(eulerAngles.x, eulerAngles.y, eulerAngles.z)); - result.Transpose(); return result; } @@ -411,7 +406,6 @@ namespace SHADE const XMVECTOR Q = XMLoadFloat4(&q); XMStoreFloat4x4(&result, XMMatrixRotationQuaternion(Q)); - result.Transpose(); return result; } @@ -420,7 +414,6 @@ namespace SHADE SHMatrix result; XMStoreFloat4x4(&result, XMMatrixRotationX(angleInRad)); - result.Transpose(); return result; } @@ -429,7 +422,6 @@ namespace SHADE SHMatrix result; XMStoreFloat4x4(&result, XMMatrixRotationY(angleInRad)); - result.Transpose(); return result; } @@ -438,7 +430,6 @@ namespace SHADE SHMatrix result; XMStoreFloat4x4(&result, XMMatrixRotationZ(angleInRad)); - result.Transpose(); return result; } @@ -476,7 +467,6 @@ namespace SHADE XMStoreFloat4x4(&result, XMMatrixLookAtRH(EYE, TGT, UP)); - result.Transpose(); return result; } @@ -490,7 +480,6 @@ namespace SHADE XMStoreFloat4x4(&result, XMMatrixLookAtLH(EYE, TGT, UP)); - result.Transpose(); return result; } @@ -512,7 +501,6 @@ namespace SHADE result._42 = pos.y; result._43 = pos.z; - result.Transpose(); return result; } @@ -534,7 +522,6 @@ namespace SHADE result._42 = pos.x; result._43 = pos.x; - result.Transpose(); return result; } @@ -544,7 +531,6 @@ namespace SHADE XMStoreFloat4x4(&result, XMMatrixPerspectiveFovRH(fov, aspectRatio, nearPlane, farPlane)); - result.Transpose(); return result; } @@ -554,7 +540,6 @@ namespace SHADE XMStoreFloat4x4(&result, XMMatrixPerspectiveFovLH(fov, aspectRatio, nearPlane, farPlane)); - result.Transpose(); return result; } @@ -564,7 +549,6 @@ namespace SHADE XMStoreFloat4x4(&result, XMMatrixPerspectiveRH(width, height, nearPlane, farPlane)); - result.Transpose(); return result; } @@ -574,7 +558,6 @@ namespace SHADE XMStoreFloat4x4(&result, XMMatrixPerspectiveLH(width, height, nearPlane, farPlane)); - result.Transpose(); return result; } @@ -584,7 +567,6 @@ namespace SHADE XMStoreFloat4x4(&result, XMMatrixOrthographicRH(width, height, nearPlane, farPlane)); - result.Transpose(); return result; } @@ -594,7 +576,6 @@ namespace SHADE XMStoreFloat4x4(&result, XMMatrixOrthographicLH(width, height, nearPlane, farPlane)); - result.Transpose(); return result; } diff --git a/SHADE_Engine/src/Math/SHMatrix.h b/SHADE_Engine/src/Math/SHMatrix.h index 96aefec3..3666fbe6 100644 --- a/SHADE_Engine/src/Math/SHMatrix.h +++ b/SHADE_Engine/src/Math/SHMatrix.h @@ -13,6 +13,8 @@ #include #include +// Project Headers +#include "SH_API.h" #include "Vector/SHVec4.h" #include "SH_API.h" @@ -50,96 +52,99 @@ namespace SHADE /* Constructors & Destructor */ /*---------------------------------------------------------------------------------*/ - SHMatrix (const SHMatrix& rhs) = default; - SHMatrix (SHMatrix&& rhs) = default; - ~SHMatrix () = default; + SHMatrix (const SHMatrix& rhs) = default; + SHMatrix (SHMatrix&& rhs) = default; + ~SHMatrix () = default; - SHMatrix () noexcept; - SHMatrix ( const SHVec4& r0, - const SHVec4& r1, - const SHVec4& r2, - const SHVec4& r3 = SHVec4::UnitW - ) noexcept; - SHMatrix ( - float m00, float m01, float m02, float m03, - float m10, float m11, float m12, float m13, - float m20, float m21, float m22, float m23, - float m30 = 0.0f, float m31 = 0.0f, float m32 = 0.0f, float m33 = 1.0f - ) noexcept; + SHMatrix () noexcept; + SHMatrix + ( + const SHVec4& r0, + const SHVec4& r1, + const SHVec4& r2, + const SHVec4& r3 = SHVec4::UnitW + ) noexcept; + SHMatrix + ( + float m00, float m01, float m02, float m03, + float m10, float m11, float m12, float m13, + float m20, float m21, float m22, float m23, + float m30 = 0.0f, float m31 = 0.0f, float m32 = 0.0f, float m33 = 1.0f + ) noexcept; /*---------------------------------------------------------------------------------*/ /* Operator Overloads */ /*---------------------------------------------------------------------------------*/ - SHMatrix& operator= (const SHMatrix& rhs) = default; - SHMatrix& operator= (SHMatrix&& rhs) = default; + SHMatrix& operator= (const SHMatrix& rhs) = default; + SHMatrix& operator= (SHMatrix&& rhs) = default; - SHMatrix& operator+= (const SHMatrix& rhs) noexcept; - SHMatrix& operator-= (const SHMatrix& rhs) noexcept; - SHMatrix& operator*= (const SHMatrix& rhs) noexcept; - SHMatrix& operator*= (float rhs) noexcept; - SHMatrix& operator/= (const SHMatrix& rhs) noexcept; - SHMatrix& operator/= (float rhs) noexcept; + SHMatrix& operator+= (const SHMatrix& rhs) noexcept; + SHMatrix& operator-= (const SHMatrix& rhs) noexcept; + SHMatrix& operator*= (const SHMatrix& rhs) noexcept; + SHMatrix& operator*= (float rhs) noexcept; + SHMatrix& operator/= (const SHMatrix& rhs) noexcept; + SHMatrix& operator/= (float rhs) noexcept; - SHMatrix operator+ (const SHMatrix& rhs) const noexcept; - SHMatrix operator- (const SHMatrix& rhs) const noexcept; - SHMatrix operator- () const noexcept; - SHMatrix operator* (const SHMatrix& rhs) const noexcept; - SHVec3 operator* (const SHVec3& rhs) const noexcept; - SHVec4 operator* (const SHVec4& rhs) const noexcept; - SHMatrix operator* (float rhs) const noexcept; - SHMatrix operator/ (const SHMatrix& rhs) const noexcept; - SHMatrix operator/ (float rhs) const noexcept; + [[nodiscard]] SHMatrix operator+ (const SHMatrix& rhs) const noexcept; + [[nodiscard]] SHMatrix operator- (const SHMatrix& rhs) const noexcept; + [[nodiscard]] SHMatrix operator- () const noexcept; + [[nodiscard]] SHMatrix operator* (const SHMatrix& rhs) const noexcept; + [[nodiscard]] SHVec3 operator* (const SHVec3& rhs) const noexcept; + [[nodiscard]] SHVec4 operator* (const SHVec4& rhs) const noexcept; + [[nodiscard]] SHMatrix operator* (float rhs) const noexcept; + [[nodiscard]] SHMatrix operator/ (const SHMatrix& rhs) const noexcept; + [[nodiscard]] SHMatrix operator/ (float rhs) const noexcept; - bool operator== (const SHMatrix& rhs) const noexcept; - bool operator!= (const SHMatrix& rhs) const noexcept; + [[nodiscard]] bool operator== (const SHMatrix& rhs) const noexcept; + [[nodiscard]] bool operator!= (const SHMatrix& rhs) const noexcept; /*---------------------------------------------------------------------------------*/ /* Function Members */ /*---------------------------------------------------------------------------------*/ - void Transpose () noexcept; - void Invert () noexcept; + void Transpose () noexcept; + void Invert () noexcept; - [[nodiscard]] float Determinant () const noexcept; - [[nodiscard]] std::string ToString () const noexcept; + [[nodiscard]] float Determinant () const noexcept; + [[nodiscard]] std::string ToString () const noexcept; /*---------------------------------------------------------------------------------*/ /* Static Function Members */ /*---------------------------------------------------------------------------------*/ - [[nodiscard]] static SHMatrix Transpose (const SHMatrix& matrix) noexcept; - [[nodiscard]] static SHMatrix Inverse (const SHMatrix& matrix) noexcept; + [[nodiscard]] static SHMatrix Transpose (const SHMatrix& matrix) noexcept; + [[nodiscard]] static SHMatrix Inverse (const SHMatrix& matrix) noexcept; - [[nodiscard]] static SHMatrix Translate (float x, float y, float z) noexcept; - [[nodiscard]] static SHMatrix Translate (const SHVec3& pos) noexcept; + [[nodiscard]] static SHMatrix Translate (float x, float y, float z) noexcept; + [[nodiscard]] static SHMatrix Translate (const SHVec3& pos) noexcept; - [[nodiscard]] static SHMatrix Rotate (const SHVec3& axis, float angleInRad) noexcept; - [[nodiscard]] static SHMatrix Rotate (float yaw, float pitch, float roll) noexcept; - [[nodiscard]] static SHMatrix Rotate (const SHVec3& eulerAngles) noexcept; - [[nodiscard]] static SHMatrix Rotate (const SHQuaternion& q) noexcept; - [[nodiscard]] static SHMatrix RotateX (float angleInRad) noexcept; - [[nodiscard]] static SHMatrix RotateY (float angleInRad) noexcept; - [[nodiscard]] static SHMatrix RotateZ (float angleInRad) noexcept; + [[nodiscard]] static SHMatrix Rotate (const SHVec3& axis, float angleInRad) noexcept; + [[nodiscard]] static SHMatrix Rotate (float yaw, float pitch, float roll) noexcept; + [[nodiscard]] static SHMatrix Rotate (const SHVec3& eulerAngles) noexcept; + [[nodiscard]] static SHMatrix Rotate (const SHQuaternion& q) noexcept; + [[nodiscard]] static SHMatrix RotateX (float angleInRad) noexcept; + [[nodiscard]] static SHMatrix RotateY (float angleInRad) noexcept; + [[nodiscard]] static SHMatrix RotateZ (float angleInRad) noexcept; - [[nodiscard]] static SHMatrix Scale (float uniformScaleFactor) noexcept; - [[nodiscard]] static SHMatrix Scale (float x, float y, float z) noexcept; - [[nodiscard]] static SHMatrix Scale (const SHVec3& scale) noexcept; + [[nodiscard]] static SHMatrix Scale (float uniformScaleFactor) noexcept; + [[nodiscard]] static SHMatrix Scale (float x, float y, float z) noexcept; + [[nodiscard]] static SHMatrix Scale (const SHVec3& scale) noexcept; - [[nodiscard]] static SHMatrix LookAtRH (const SHVec3& eye, const SHVec3& target, const SHVec3& up) noexcept; - [[nodiscard]] static SHMatrix LookAtLH (const SHVec3& eye, const SHVec3& target, const SHVec3& up) noexcept; - [[nodiscard]] static SHMatrix CamToWorldRH (const SHVec3& pos, const SHVec3& forward, const SHVec3& up) noexcept; - [[nodiscard]] static SHMatrix CamToWorldLH (const SHVec3& pos, const SHVec3& forward, const SHVec3& up) noexcept; - [[nodiscard]] static SHMatrix PerspectiveFovRH (float fov, float aspectRatio, float nearPlane, float farPlane) noexcept; - [[nodiscard]] static SHMatrix PerspectiveFovLH (float fov, float aspectRatio, float nearPlane, float farPlane) noexcept; - [[nodiscard]] static SHMatrix PerspectiveRH (float width, float height, float nearPlane, float farPlane) noexcept; - [[nodiscard]] static SHMatrix PerspectiveLH (float width, float height, float nearPlane, float farPlane) noexcept; - [[nodiscard]] static SHMatrix OrthographicRH (float width, float height, float nearPlane, float farPlane) noexcept; - [[nodiscard]] static SHMatrix OrthographicLH (float width, float height, float nearPlane, float farPlane) noexcept; + [[nodiscard]] static SHMatrix LookAtRH (const SHVec3& eye, const SHVec3& target, const SHVec3& up) noexcept; + [[nodiscard]] static SHMatrix LookAtLH (const SHVec3& eye, const SHVec3& target, const SHVec3& up) noexcept; + [[nodiscard]] static SHMatrix CamToWorldRH (const SHVec3& pos, const SHVec3& forward, const SHVec3& up) noexcept; + [[nodiscard]] static SHMatrix CamToWorldLH (const SHVec3& pos, const SHVec3& forward, const SHVec3& up) noexcept; + [[nodiscard]] static SHMatrix PerspectiveFovRH (float fov, float aspectRatio, float nearPlane, float farPlane) noexcept; + [[nodiscard]] static SHMatrix PerspectiveFovLH (float fov, float aspectRatio, float nearPlane, float farPlane) noexcept; + [[nodiscard]] static SHMatrix PerspectiveRH (float width, float height, float nearPlane, float farPlane) noexcept; + [[nodiscard]] static SHMatrix PerspectiveLH (float width, float height, float nearPlane, float farPlane) noexcept; + [[nodiscard]] static SHMatrix OrthographicRH (float width, float height, float nearPlane, float farPlane) noexcept; + [[nodiscard]] static SHMatrix OrthographicLH (float width, float height, float nearPlane, float farPlane) noexcept; // TODO(Diren): Billboard, Shadow, Projection & Reflection }; - SHMatrix operator*(float lhs, const SHMatrix& rhs) noexcept; + SHMatrix operator*(float lhs, const SHMatrix& rhs) noexcept; } // namespace SHADE \ No newline at end of file diff --git a/SHADE_Engine/src/Math/SHQuaternion.cpp b/SHADE_Engine/src/Math/SHQuaternion.cpp index 208f131d..36921f3f 100644 --- a/SHADE_Engine/src/Math/SHQuaternion.cpp +++ b/SHADE_Engine/src/Math/SHQuaternion.cpp @@ -180,6 +180,34 @@ namespace SHADE return rhs * lhs; } + /*-----------------------------------------------------------------------------------*/ + /* Getter Function Definitions */ + /*-----------------------------------------------------------------------------------*/ + + float SHQuaternion::GetAngle() const noexcept + { + XMVECTOR axis; + float angle; + + const XMVECTOR Q = XMLoadFloat4(this); + XMQuaternionToAxisAngle(&axis, &angle, Q); + return angle; + } + + SHVec4 SHQuaternion::GetAxisAngle() const noexcept + { + XMVECTOR axis; + float angle; + + const XMVECTOR Q = XMLoadFloat4(this); + XMQuaternionToAxisAngle(&axis, &angle, Q); + + + return SHVec4{XMVectorGetX(axis), XMVectorGetY(axis), XMVectorGetZ(axis), angle}; + } + + + /*-----------------------------------------------------------------------------------*/ /* Function Member Definitions */ /*-----------------------------------------------------------------------------------*/ @@ -230,7 +258,7 @@ namespace SHADE { std::stringstream ss; ss << std::fixed << std::setprecision(3); - ss << "<" << x << ", " << y << ", " << z << ", " << w <<">"; + ss << "<" << w << ", " << x << ", " << y << ", " << z <<">"; return ss.str(); } diff --git a/SHADE_Engine/src/Math/SHQuaternion.h b/SHADE_Engine/src/Math/SHQuaternion.h index 27088284..61b55ef9 100644 --- a/SHADE_Engine/src/Math/SHQuaternion.h +++ b/SHADE_Engine/src/Math/SHQuaternion.h @@ -13,6 +13,9 @@ #include #include +// Project Headers +#include "SH_API.h" + namespace SHADE { /*-----------------------------------------------------------------------------------*/ @@ -20,13 +23,14 @@ namespace SHADE /*-----------------------------------------------------------------------------------*/ class SHVec3; + class SHVec4; class SHMatrix; /*-----------------------------------------------------------------------------------*/ /* Type Definitions */ /*-----------------------------------------------------------------------------------*/ - class SHQuaternion : public DirectX::XMFLOAT4 + class SH_API SHQuaternion : public DirectX::XMFLOAT4 { public: /*---------------------------------------------------------------------------------*/ @@ -39,68 +43,75 @@ namespace SHADE /* Constructors & Destructor */ /*---------------------------------------------------------------------------------*/ - SHQuaternion (const SHQuaternion& rhs) = default; - SHQuaternion (SHQuaternion&& rhs) = default; + SHQuaternion (const SHQuaternion& rhs) = default; + SHQuaternion (SHQuaternion&& rhs) = default; - SHQuaternion () noexcept; - SHQuaternion (float x, float y, float z, float w) noexcept; - SHQuaternion (float yaw, float pitch, float roll) noexcept; - SHQuaternion (const SHVec3& eulerAngles) noexcept; - SHQuaternion (const SHVec3& axis, float angleInRad) noexcept; - SHQuaternion (const SHMatrix& rotationMatrix) noexcept; + SHQuaternion () noexcept; + SHQuaternion (float x, float y, float z, float w) noexcept; + SHQuaternion (float yaw, float pitch, float roll) noexcept; + SHQuaternion (const SHVec3& eulerAngles) noexcept; + SHQuaternion (const SHVec3& axis, float angleInRad) noexcept; + SHQuaternion (const SHMatrix& rotationMatrix) noexcept; /*---------------------------------------------------------------------------------*/ /* Operator Overloads */ /*---------------------------------------------------------------------------------*/ - [[nodiscard]] SHQuaternion& operator= (const SHQuaternion& rhs) = default; - [[nodiscard]] SHQuaternion& operator= (SHQuaternion&& rhs) = default; + SHQuaternion& operator= (const SHQuaternion& rhs) = default; + SHQuaternion& operator= (SHQuaternion&& rhs) = default; + + SHQuaternion& operator+= (const SHQuaternion& rhs) noexcept; + SHQuaternion& operator-= (const SHQuaternion& rhs) noexcept; + SHQuaternion& operator*= (const SHQuaternion& rhs) noexcept; + SHQuaternion& operator*= (float rhs) noexcept; + SHQuaternion& operator/= (const SHQuaternion& rhs) noexcept; - [[nodiscard]] SHQuaternion& operator+= (const SHQuaternion& rhs) noexcept; - [[nodiscard]] SHQuaternion& operator-= (const SHQuaternion& rhs) noexcept; - [[nodiscard]] SHQuaternion& operator*= (const SHQuaternion& rhs) noexcept; - [[nodiscard]] SHQuaternion& operator*= (float rhs) noexcept; - [[nodiscard]] SHQuaternion& operator/= (const SHQuaternion& rhs) noexcept; + [[nodiscard]] SHQuaternion operator+ (const SHQuaternion& rhs) const noexcept; + [[nodiscard]] SHQuaternion operator- (const SHQuaternion& rhs) const noexcept; + [[nodiscard]] SHQuaternion operator- () const noexcept; + [[nodiscard]] SHQuaternion operator* (const SHQuaternion& rhs) const noexcept; + [[nodiscard]] SHQuaternion operator* (float rhs) const noexcept; + [[nodiscard]] SHQuaternion operator/ (const SHQuaternion& rhs) const noexcept; - [[nodiscard]] SHQuaternion operator+ (const SHQuaternion& rhs) const noexcept; - [[nodiscard]] SHQuaternion operator- (const SHQuaternion& rhs) const noexcept; - [[nodiscard]] SHQuaternion operator- () const noexcept; - [[nodiscard]] SHQuaternion operator* (const SHQuaternion& rhs) const noexcept; - [[nodiscard]] SHQuaternion operator* (float rhs) const noexcept; - [[nodiscard]] SHQuaternion operator/ (const SHQuaternion& rhs) const noexcept; + [[nodiscard]] bool operator== (const SHQuaternion& rhs) const noexcept; + [[nodiscard]] bool operator!= (const SHQuaternion& rhs) const noexcept; - [[nodiscard]] bool operator== (const SHQuaternion& rhs) const noexcept; - [[nodiscard]] bool operator!= (const SHQuaternion& rhs) const noexcept; + /*---------------------------------------------------------------------------------*/ + /* Getter Functions */ + /*---------------------------------------------------------------------------------*/ + + [[nodiscard]] float GetAngle () const noexcept; + [[nodiscard]] SHVec4 GetAxisAngle () const noexcept; /*---------------------------------------------------------------------------------*/ /* Function Members */ /*---------------------------------------------------------------------------------*/ - void Invert () noexcept; + void Invert () noexcept; - [[nodiscard]] float Length () const noexcept; - [[nodiscard]] float LengthSquared () const noexcept; - [[nodiscard]] float Dot (const SHQuaternion& rhs) const noexcept; - [[nodiscard]] SHQuaternion RotateTowards (const SHQuaternion& target, float maxAngleInRad) const noexcept; + [[nodiscard]] float Length () const noexcept; + [[nodiscard]] float LengthSquared () const noexcept; + [[nodiscard]] float Dot (const SHQuaternion& rhs) const noexcept; + [[nodiscard]] SHQuaternion RotateTowards (const SHQuaternion& target, float maxAngleInRad) const noexcept; - [[nodiscard]] SHVec3 ToEuler () const noexcept; - [[nodiscard]] std::string ToString () const noexcept; + [[nodiscard]] SHVec3 ToEuler () const noexcept; + [[nodiscard]] std::string ToString () const noexcept; /*---------------------------------------------------------------------------------*/ /* Static Function Members */ /*---------------------------------------------------------------------------------*/ - [[nodiscard]] static SHQuaternion Normalise (const SHQuaternion& q) noexcept; - [[nodiscard]] static SHQuaternion Conjugate (const SHQuaternion& q) noexcept; - [[nodiscard]] static SHQuaternion Inverse (const SHQuaternion& q) noexcept; - [[nodiscard]] static float Angle (const SHQuaternion& q1, const SHQuaternion& q2) noexcept; + [[nodiscard]] static SHQuaternion Normalise (const SHQuaternion& q) noexcept; + [[nodiscard]] static SHQuaternion Conjugate (const SHQuaternion& q) noexcept; + [[nodiscard]] static SHQuaternion Inverse (const SHQuaternion& q) noexcept; + [[nodiscard]] static float Angle (const SHQuaternion& q1, const SHQuaternion& q2) noexcept; - [[nodiscard]] static SHQuaternion Lerp (const SHQuaternion& q1, const SHQuaternion& q2, float t) noexcept; - [[nodiscard]] static SHQuaternion Slerp (const SHQuaternion& q1, const SHQuaternion& q2, float t) noexcept; + [[nodiscard]] static SHQuaternion Lerp (const SHQuaternion& q1, const SHQuaternion& q2, float t) noexcept; + [[nodiscard]] static SHQuaternion Slerp (const SHQuaternion& q1, const SHQuaternion& q2, float t) noexcept; - [[nodiscard]] static SHQuaternion Rotate (const SHVec3& from, const SHVec3& to) noexcept; + [[nodiscard]] static SHQuaternion Rotate (const SHVec3& from, const SHVec3& to) noexcept; }; - SHQuaternion operator*(float lhs, const SHQuaternion& rhs) noexcept; + SHQuaternion operator*(float lhs, const SHQuaternion& rhs) noexcept; } // namespace SHADE \ No newline at end of file diff --git a/SHADE_Engine/src/Math/Transform/SHTransform.cpp b/SHADE_Engine/src/Math/Transform/SHTransform.cpp new file mode 100644 index 00000000..f51d73ec --- /dev/null +++ b/SHADE_Engine/src/Math/Transform/SHTransform.cpp @@ -0,0 +1,70 @@ +/**************************************************************************************** + * \file SHTransform.cpp + * \author Diren D Bharwani, diren.dbharwani, 390002520 + * \brief Implementation for a Transform. + * + * \copyright Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or + * disclosure of this file or its contents without the prior written consent + * of DigiPen Institute of Technology is prohibited. +****************************************************************************************/ + +#include + +// Primary Header +#include "SHTransform.h" + +namespace SHADE +{ + /*-----------------------------------------------------------------------------------*/ + /* Static Data Member Definitions */ + /*-----------------------------------------------------------------------------------*/ + + const SHTransform SHTransform::Identity { SHVec3::Zero, SHVec3::Zero, SHVec3::One }; + + /*-----------------------------------------------------------------------------------*/ + /* Constructors & Destructor Definitions */ + /*-----------------------------------------------------------------------------------*/ + + SHTransform::SHTransform() noexcept + : position { SHVec3::Zero } + , rotation { SHVec3::Zero } + , scale { SHVec3::One } + {} + + SHTransform::SHTransform(const SHVec3& pos, const SHVec3& rot, const SHVec3& scl) noexcept + : position { pos } + , rotation { rot } + , scale { scl } + {} + + /*-----------------------------------------------------------------------------------*/ + /* Operator Overload Definitions */ + /*-----------------------------------------------------------------------------------*/ + + bool SHTransform::operator==(const SHTransform& rhs) const noexcept + { + return !(position != rhs.position || rotation != rhs.rotation || scale != rhs.scale); + } + + bool SHTransform::operator!=(const SHTransform& rhs) const noexcept + { + return (position != rhs.position || rotation != rhs.rotation || scale != rhs.scale); + } + + /*-----------------------------------------------------------------------------------*/ + /* Public Function Member Definitions */ + /*-----------------------------------------------------------------------------------*/ + + const SHMatrix& SHTransform::ComputeTRS() + { + + const SHMatrix T = SHMatrix::Translate(position); + const SHMatrix R = SHMatrix::Rotate(rotation); + const SHMatrix S = SHMatrix::Scale(scale); + + trs = S * R * T; + + return trs; + } + +} // namespace SHADE \ No newline at end of file diff --git a/SHADE_Engine/src/Math/Transform/SHTransform.h b/SHADE_Engine/src/Math/Transform/SHTransform.h new file mode 100644 index 00000000..9edd7fdd --- /dev/null +++ b/SHADE_Engine/src/Math/Transform/SHTransform.h @@ -0,0 +1,67 @@ +/**************************************************************************************** + * \file SHTransform.h + * \author Diren D Bharwani, diren.dbharwani, 390002520 + * \brief Interface for a Transform. + * + * \copyright Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or + * disclosure of this file or its contents without the prior written consent + * of DigiPen Institute of Technology is prohibited. +****************************************************************************************/ + +#pragma once + +// Project Headers +#include "SH_API.h" +#include "Math/SHMath.h" + +namespace SHADE +{ + /*-----------------------------------------------------------------------------------*/ + /* Type Definitions */ + /*-----------------------------------------------------------------------------------*/ + + struct SH_API SHTransform + { + public: + /*---------------------------------------------------------------------------------*/ + /* Data Members */ + /*---------------------------------------------------------------------------------*/ + + static const SHTransform Identity; + + SHVec3 position; + SHVec3 rotation; + SHVec3 scale; + + SHMatrix trs; + + /*---------------------------------------------------------------------------------*/ + /* Constructors & Destructor */ + /*---------------------------------------------------------------------------------*/ + + SHTransform (const SHTransform&) = default; + SHTransform (SHTransform&&) = default; + ~SHTransform () = default; + + SHTransform () noexcept; + SHTransform (const SHVec3& pos, const SHVec3& rot, const SHVec3& scl) noexcept; + + /*---------------------------------------------------------------------------------*/ + /* Operator Overloads */ + /*---------------------------------------------------------------------------------*/ + + SHTransform& operator= (const SHTransform&) = default; + SHTransform& operator= (SHTransform&&) = default; + + [[nodiscard]] bool operator==(const SHTransform& rhs) const noexcept; + [[nodiscard]] bool operator!=(const SHTransform& rhs) const noexcept; + + /*---------------------------------------------------------------------------------*/ + /* Function Members */ + /*---------------------------------------------------------------------------------*/ + + const SHMatrix& ComputeTRS(); + + }; + +} // namespace SHADE \ No newline at end of file diff --git a/SHADE_Engine/src/Math/Transform/SHTransformComponent.cpp b/SHADE_Engine/src/Math/Transform/SHTransformComponent.cpp new file mode 100644 index 00000000..cdc5105f --- /dev/null +++ b/SHADE_Engine/src/Math/Transform/SHTransformComponent.cpp @@ -0,0 +1,184 @@ +/**************************************************************************************** + * \file SHTransformComponent.cpp + * \author Diren D Bharwani, diren.dbharwani, 390002520 + * \brief Implementation for a Transform Component + * + * \copyright Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or + * disclosure of this file or its contents without the prior written consent + * of DigiPen Institute of Technology is prohibited. +****************************************************************************************/ + +#include + +// Primary Header +#include "SHTransformComponent.h" + +namespace SHADE +{ + /*-----------------------------------------------------------------------------------*/ + /* Constructors & Destructor Definitions */ + /*-----------------------------------------------------------------------------------*/ + + SHTransformComponent::SHTransformComponent() noexcept + : SHComponent {} + , dirty { true } + {} + + SHTransformComponent::SHTransformComponent(const SHTransformComponent& rhs) noexcept + : SHComponent {} + , dirty { true } + , local { rhs.local } + , world { rhs.world } + {} + + SHTransformComponent::SHTransformComponent(SHTransformComponent&& rhs) noexcept + : SHComponent {} + , dirty { true } + , local { std::move(rhs.local) } + , world { std::move(rhs.world) } + {} + + /*-----------------------------------------------------------------------------------*/ + /* Operator Overload Definitions */ + /*-----------------------------------------------------------------------------------*/ + + SHTransformComponent& SHTransformComponent::operator=(const SHTransformComponent& rhs) noexcept + { + dirty = true; + local = rhs.local; + world = rhs.world; + + return *this; + } + + SHTransformComponent& SHTransformComponent::operator=(SHTransformComponent&& rhs) noexcept + { + dirty = true; + local = std::move(rhs.local); + world = std::move(rhs.world); + + return *this; + } + + + /*-----------------------------------------------------------------------------------*/ + /* Getter Function Definitions */ + /*-----------------------------------------------------------------------------------*/ + + bool SHTransformComponent::HasChanged() const noexcept + { + return dirty; + } + + const SHVec3& SHTransformComponent::GetLocalPosition() const noexcept + { + return local.position; + } + + const SHVec3& SHTransformComponent::GetLocalRotation() const noexcept + { + return local.rotation; + } + + const SHVec3& SHTransformComponent::GetLocalScale() const noexcept + { + return local.scale; + } + + const SHVec3& SHTransformComponent::GetWorldPosition() const noexcept + { + return world.position; + } + + const SHVec3& SHTransformComponent::GetWorldRotation() const noexcept + { + return world.rotation; + } + + const SHVec3& SHTransformComponent::GetWorldScale() const noexcept + { + return world.scale; + } + + const SHMatrix& SHTransformComponent::GetLocalToWorld() const noexcept + { + return local.trs; + } + + SHMatrix SHTransformComponent::GetWorldToLocal() const noexcept + { + return SHMatrix::Inverse(local.trs); + } + + const SHMatrix& SHTransformComponent::GetTRS() const noexcept + { + return world.trs; + } + + /*-----------------------------------------------------------------------------------*/ + /* Setter Function Definitions */ + /*-----------------------------------------------------------------------------------*/ + + void SHTransformComponent::SetLocalPosition(const SHVec3& newLocalPosition) noexcept + { + dirty = true; + local.position = newLocalPosition; + } + + void SHTransformComponent::SetLocalRotation(const SHVec3& newLocalRotation) noexcept + { + dirty = true; + local.rotation = newLocalRotation; + } + + void SHTransformComponent::SetLocalRotation(float pitch, float yaw, float roll) noexcept + { + dirty = true; + + local.rotation.x = pitch; + local.rotation.y = yaw; + local.rotation.z = roll; + } + + void SHTransformComponent::SetLocalScale(const SHVec3& newLocalScale) noexcept + { + dirty = true; + local.scale = newLocalScale; + } + + void SHTransformComponent::SetWorldPosition(const SHVec3& newWorldPosition) noexcept + { + dirty = true; + + world.position = newWorldPosition; + updateQueue.push({ UpdateCommandType::WORLD_POSITION, newWorldPosition }); + } + + void SHTransformComponent::SetWorldRotation(const SHVec3& newWorldRotation) noexcept + { + dirty = true; + + world.rotation = newWorldRotation; + updateQueue.push({ UpdateCommandType::WORLD_ROTATION, newWorldRotation }); + } + + void SHTransformComponent::SetWorldRotation(float pitch, float yaw, float roll) noexcept + { + dirty = true; + + world.rotation.x = pitch; + world.rotation.y = yaw; + world.rotation.z = roll; + + updateQueue.push({ UpdateCommandType::WORLD_ROTATION, SHVec3{ pitch, yaw, roll} }); + } + + void SHTransformComponent::SetWorldScale(const SHVec3& newWorldScale) noexcept + { + dirty = true; + + world.scale = newWorldScale; + updateQueue.push({ UpdateCommandType::WORLD_SCALE, newWorldScale }); + } + +} // namespace SHADE \ No newline at end of file diff --git a/SHADE_Engine/src/Math/Transform/SHTransformComponent.h b/SHADE_Engine/src/Math/Transform/SHTransformComponent.h new file mode 100644 index 00000000..7f7dd473 --- /dev/null +++ b/SHADE_Engine/src/Math/Transform/SHTransformComponent.h @@ -0,0 +1,122 @@ +/**************************************************************************************** + * \file SHTransformComponent.h + * \author Diren D Bharwani, diren.dbharwani, 390002520 + * \brief Interface for a Transform Component + * + * \copyright Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or + * disclosure of this file or its contents without the prior written consent + * of DigiPen Institute of Technology is prohibited. +****************************************************************************************/ + +#pragma once + +#include + +// Project Headers +#include "SH_API.h" +#include "ECS_Base/Components/SHComponent.h" +#include "SHTransform.h" + +namespace SHADE +{ + /*-----------------------------------------------------------------------------------*/ + /* Type Definitions */ + /*-----------------------------------------------------------------------------------*/ + + class SH_API SHTransformComponent : public SHComponent + { + private: + /*---------------------------------------------------------------------------------*/ + /* Friends */ + /*---------------------------------------------------------------------------------*/ + + friend class SHTransformSystem; + + public: + /*---------------------------------------------------------------------------------*/ + /* Constructors & Destructor */ + /*---------------------------------------------------------------------------------*/ + + ~SHTransformComponent () override = default; + + SHTransformComponent () noexcept; + SHTransformComponent (const SHTransformComponent& rhs) noexcept; + SHTransformComponent (SHTransformComponent&& rhs) noexcept; + + /*---------------------------------------------------------------------------------*/ + /* Operator Overloads */ + /*---------------------------------------------------------------------------------*/ + + SHTransformComponent& operator=(const SHTransformComponent& rhs) noexcept; + SHTransformComponent& operator=(SHTransformComponent&& rhs) noexcept; + + /*---------------------------------------------------------------------------------*/ + /* Getter Functions */ + /*---------------------------------------------------------------------------------*/ + + [[nodiscard]] bool HasChanged () const noexcept; + + [[nodiscard]] const SHVec3& GetLocalPosition () const noexcept; + [[nodiscard]] const SHVec3& GetLocalRotation () const noexcept; + [[nodiscard]] const SHVec3& GetLocalScale () const noexcept; + [[nodiscard]] const SHVec3& GetWorldPosition () const noexcept; + [[nodiscard]] const SHVec3& GetWorldRotation () const noexcept; + [[nodiscard]] const SHVec3& GetWorldScale () const noexcept; + + [[nodiscard]] const SHMatrix& GetLocalToWorld () const noexcept; + [[nodiscard]] SHMatrix GetWorldToLocal () const noexcept; + + [[nodiscard]] const SHMatrix& GetTRS () const noexcept; + + /*---------------------------------------------------------------------------------*/ + /* Setter Functions */ + /*---------------------------------------------------------------------------------*/ + + void SetLocalPosition (const SHVec3& newLocalPosition) noexcept; + void SetLocalRotation (const SHVec3& newLocalRotation) noexcept; + void SetLocalRotation (float pitch, float yaw, float roll) noexcept; + void SetLocalScale (const SHVec3& newLocalScale) noexcept; + void SetWorldPosition (const SHVec3& newWorldPosition) noexcept; + void SetWorldRotation (const SHVec3& newWorldRotation) noexcept; + void SetWorldRotation (float pitch, float yaw, float roll) noexcept; + void SetWorldScale (const SHVec3& newWorldScale) noexcept; + + private: + /*---------------------------------------------------------------------------------*/ + /* Type Definitions */ + /*---------------------------------------------------------------------------------*/ + + enum class UpdateCommandType + { + WORLD_POSITION + , WORLD_ROTATION + , WORLD_SCALE + }; + + struct UpdateCommand + { + public: + /*-------------------------------------------------------------------------------*/ + /* Data Members */ + /*-------------------------------------------------------------------------------*/ + + UpdateCommandType type; + SHVec3 data; + }; + + using UpdateQueue = std::queue; + + /*---------------------------------------------------------------------------------*/ + /* Data Members */ + /*---------------------------------------------------------------------------------*/ + + bool dirty; + + SHTransform local; // Local TRS holds Local To World Transform + SHTransform world; + + UpdateQueue updateQueue; + }; + + +} // namespace SHADE \ No newline at end of file diff --git a/SHADE_Engine/src/Math/Transform/SHTransformSystem.cpp b/SHADE_Engine/src/Math/Transform/SHTransformSystem.cpp new file mode 100644 index 00000000..879c2d34 --- /dev/null +++ b/SHADE_Engine/src/Math/Transform/SHTransformSystem.cpp @@ -0,0 +1,139 @@ +/**************************************************************************************** + * \file SHTransformSystem.cpp + * \author Diren D Bharwani, diren.dbharwani, 390002520 + * \brief Implementation for the Transform System + * + * \copyright Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or + * disclosure of this file or its contents without the prior written consent + * of DigiPen Institute of Technology is prohibited. +****************************************************************************************/ + +#include + +// Primary Header +#include "SHTransformSystem.h" + +// Project Headers +#include "Scene/SHSceneManager.h" +#include "ECS_Base/Managers/SHComponentManager.h" +#include "ECS_Base/Managers/SHEntityManager.h" +#include "Tools/SHException.h" + +namespace SHADE +{ + /*-----------------------------------------------------------------------------------*/ + /* Constructors & Destructor Definitions */ + /*-----------------------------------------------------------------------------------*/ + + SHTransformSystem::SHTransformSystem() + : SHSystemRoutine { "Transform Routine", false } + {} + + + /*-----------------------------------------------------------------------------------*/ + /* Public Function Member Definitions */ + /*-----------------------------------------------------------------------------------*/ + + void SHTransformSystem::Execute(double dt) noexcept + { + // Get the current scene graph to traverse and update + const auto& SCENE_GRAPH = SHSceneManager::GetCurrentSceneGraph(); + UpdateEntity(SCENE_GRAPH.GetRoot()); + } + + /*-----------------------------------------------------------------------------------*/ + /* Private Function Member Definitions */ + /*-----------------------------------------------------------------------------------*/ + + void SHTransformSystem::UpdateEntity(const SHSceneNode* node) + { + const auto* NODE_TRANSFORM = SHComponentManager::GetComponent_s(node->GetEntityID()); + const bool HAS_PARENT_CHANGED = NODE_TRANSFORM && NODE_TRANSFORM->dirty; + + for (const auto* child : node->GetChildren()) + { + // Active states of entities should sync with scene nodes + const bool IS_NODE_ACTIVE = child->isActive; + + #ifdef _DEBUG + const bool IS_ENTITY_ACTIVE = SHEntityManager::GetEntityByID(child->GetEntityID())->GetActive(); + SHASSERT(IS_NODE_ACTIVE == IS_ENTITY_ACTIVE, "Entity and Node active states are not synced!") + #endif + + if (!IS_NODE_ACTIVE) + { + UpdateEntity(child); + continue; + } + + const bool HAS_TRANSFORM = SHComponentManager::HasComponent(child->GetEntityID()); + if (!HAS_TRANSFORM) + continue; + + auto* childTransform = SHComponentManager::GetComponent(child->GetEntityID()); + + if (childTransform->dirty || HAS_PARENT_CHANGED) + UpdateTransform(*childTransform, NODE_TRANSFORM); + + UpdateEntity(child); + + // Clear dirty flag after all children are updated + childTransform->dirty = false; + } + } + + void SHTransformSystem::UpdateTransform(SHTransformComponent& tf, const SHTransformComponent* parent) + { + SHMatrix localToWorld = SHMatrix::Identity; + SHMatrix worldToLocal = SHMatrix::Identity; + + if (parent) + { + localToWorld = parent->GetTRS(); + worldToLocal = SHMatrix::Inverse(tf.local.trs); + } + + while (!tf.updateQueue.empty()) + { + const auto& UPDATE_COMMAND = tf.updateQueue.front(); + + switch (UPDATE_COMMAND.type) + { + case SHTransformComponent::UpdateCommandType::WORLD_POSITION: + { + tf.local.position = SHVec3::Transform(UPDATE_COMMAND.data, worldToLocal); + break; + } + case SHTransformComponent::UpdateCommandType::WORLD_ROTATION: + { + tf.local.rotation = tf.world.rotation; + if (parent) + tf.local.rotation -= parent->GetLocalRotation(); + + break; + } + case SHTransformComponent::UpdateCommandType::WORLD_SCALE: + { + tf.local.scale = tf.world.scale; + if (parent) + tf.local.scale /= parent->GetLocalScale(); + + break; + } + // Redundant + default: break; + } + + tf.updateQueue.pop(); + } + + tf.local.trs = localToWorld; + + tf.world.position = SHVec3::Transform(tf.local.position, localToWorld); + tf.world.rotation = tf.local.rotation + (parent ? parent->GetLocalRotation() : SHVec3::Zero); + tf.world.scale = tf.local.scale * (parent ? parent->GetLocalScale() : SHVec3::One); + + tf.world.ComputeTRS(); + } + +} // namespace SHADE \ No newline at end of file diff --git a/SHADE_Engine/src/Math/Transform/SHTransformSystem.h b/SHADE_Engine/src/Math/Transform/SHTransformSystem.h new file mode 100644 index 00000000..5eebd292 --- /dev/null +++ b/SHADE_Engine/src/Math/Transform/SHTransformSystem.h @@ -0,0 +1,61 @@ +/**************************************************************************************** + * \file SHTransformSystem.h + * \author Diren D Bharwani, diren.dbharwani, 390002520 + * \brief Interface for the Transform System + * + * \copyright Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or + * disclosure of this file or its contents without the prior written consent + * of DigiPen Institute of Technology is prohibited. +****************************************************************************************/ + +#pragma once + +// Project Headers +#include "SHTransformComponent.h" +#include "Scene/SHSceneGraph.h" +#include "ECS_Base/System/SHSystemRoutine.h" + +namespace SHADE +{ + /*-----------------------------------------------------------------------------------*/ + /* Type Definitions */ + /*-----------------------------------------------------------------------------------*/ + + class SH_API SHTransformSystem : public SHSystemRoutine + { + public: + + /*---------------------------------------------------------------------------------*/ + /* Constructors & Destructor */ + /*---------------------------------------------------------------------------------*/ + + SHTransformSystem (); + ~SHTransformSystem () = default; + + SHTransformSystem (const SHTransformSystem&) = delete; + SHTransformSystem (SHTransformSystem&&) = delete; + + /*---------------------------------------------------------------------------------*/ + /* Operator Overloads */ + /*---------------------------------------------------------------------------------*/ + + SHTransformSystem& operator= (const SHTransformSystem&) = delete; + SHTransformSystem& operator= (SHTransformSystem&&) = delete; + + /*---------------------------------------------------------------------------------*/ + /* Function Members */ + /*---------------------------------------------------------------------------------*/ + + void Execute(double dt) noexcept override; + + private: + /*---------------------------------------------------------------------------------*/ + /* Function Members */ + /*---------------------------------------------------------------------------------*/ + + static void UpdateEntity (const SHSceneNode* node); + static void UpdateTransform(SHTransformComponent& tf, const SHTransformComponent* parent = nullptr); + }; + + +} // namespace SHADE \ No newline at end of file diff --git a/SHADE_Engine/src/Math/Vector/SHVec2.cpp b/SHADE_Engine/src/Math/Vector/SHVec2.cpp index 72c80a50..2d2eafd2 100644 --- a/SHADE_Engine/src/Math/Vector/SHVec2.cpp +++ b/SHADE_Engine/src/Math/Vector/SHVec2.cpp @@ -38,6 +38,10 @@ namespace SHADE : XMFLOAT2( 0.0f, 0.0f ) {} + SHVec2::SHVec2(float n) noexcept + : XMFLOAT2( n, n ) + {} + SHVec2::SHVec2(float _x, float _y) noexcept : XMFLOAT2( _x, _y ) {} diff --git a/SHADE_Engine/src/Math/Vector/SHVec2.h b/SHADE_Engine/src/Math/Vector/SHVec2.h index a64d4bb0..3e6287aa 100644 --- a/SHADE_Engine/src/Math/Vector/SHVec2.h +++ b/SHADE_Engine/src/Math/Vector/SHVec2.h @@ -14,6 +14,9 @@ #include #include +// Project Headers +#include "SH_API.h" + namespace SHADE { /*-----------------------------------------------------------------------------------*/ @@ -25,7 +28,7 @@ namespace SHADE /* Type Definitions */ /*-----------------------------------------------------------------------------------*/ - class SHVec2 : public DirectX::XMFLOAT2 + class SH_API SHVec2 : public DirectX::XMFLOAT2 { public: /*---------------------------------------------------------------------------------*/ @@ -45,53 +48,54 @@ namespace SHADE /* Constructors & Destructor */ /*---------------------------------------------------------------------------------*/ - SHVec2 (const SHVec2& rhs) = default; - SHVec2 (SHVec2&& rhs) = default; - ~SHVec2 () = default; + SHVec2 (const SHVec2& rhs) = default; + SHVec2 (SHVec2&& rhs) = default; + ~SHVec2 () = default; - SHVec2 () noexcept; - SHVec2 (float x, float y) noexcept; + SHVec2 () noexcept; + SHVec2 (float n) noexcept; + SHVec2 (float x, float y) noexcept; /*---------------------------------------------------------------------------------*/ /* Operator Overloads */ /*---------------------------------------------------------------------------------*/ - [[nodiscard]] SHVec2& operator= (const SHVec2& rhs) = default; - [[nodiscard]] SHVec2& operator= (SHVec2&& rhs) = default; + SHVec2& operator= (const SHVec2& rhs) = default; + SHVec2& operator= (SHVec2&& rhs) = default; - [[nodiscard]] SHVec2& operator+= (const SHVec2& rhs) noexcept; - [[nodiscard]] SHVec2& operator-= (const SHVec2& rhs) noexcept; - [[nodiscard]] SHVec2& operator*= (const SHVec2& rhs) noexcept; - [[nodiscard]] SHVec2& operator*= (float rhs) noexcept; - [[nodiscard]] SHVec2& operator/= (const SHVec2& rhs) noexcept; - [[nodiscard]] SHVec2& operator/= (float rhs) noexcept; + SHVec2& operator+= (const SHVec2& rhs) noexcept; + SHVec2& operator-= (const SHVec2& rhs) noexcept; + SHVec2& operator*= (const SHVec2& rhs) noexcept; + SHVec2& operator*= (float rhs) noexcept; + SHVec2& operator/= (const SHVec2& rhs) noexcept; + SHVec2& operator/= (float rhs) noexcept; - [[nodiscard]] SHVec2 operator+ (const SHVec2& rhs) const noexcept; - [[nodiscard]] SHVec2 operator- (const SHVec2& rhs) const noexcept; - [[nodiscard]] SHVec2 operator- () const noexcept; - [[nodiscard]] SHVec2 operator* (const SHVec2& rhs) const noexcept; - [[nodiscard]] SHVec2 operator* (float rhs) const noexcept; - [[nodiscard]] SHVec2 operator/ (const SHVec2& rhs) const noexcept; - [[nodiscard]] SHVec2 operator/ (float rhs) const noexcept; + [[nodiscard]] SHVec2 operator+ (const SHVec2& rhs) const noexcept; + [[nodiscard]] SHVec2 operator- (const SHVec2& rhs) const noexcept; + [[nodiscard]] SHVec2 operator- () const noexcept; + [[nodiscard]] SHVec2 operator* (const SHVec2& rhs) const noexcept; + [[nodiscard]] SHVec2 operator* (float rhs) const noexcept; + [[nodiscard]] SHVec2 operator/ (const SHVec2& rhs) const noexcept; + [[nodiscard]] SHVec2 operator/ (float rhs) const noexcept; - [[nodiscard]] bool operator== (const SHVec2& rhs) const noexcept; - [[nodiscard]] bool operator!= (const SHVec2& rhs) const noexcept; + [[nodiscard]] bool operator== (const SHVec2& rhs) const noexcept; + [[nodiscard]] bool operator!= (const SHVec2& rhs) const noexcept; - [[nodiscard]] float operator[] (int index); - [[nodiscard]] float operator[] (size_t index); - [[nodiscard]] float operator[] (int index) const; - [[nodiscard]] float operator[] (size_t index) const; + [[nodiscard]] float operator[] (int index); + [[nodiscard]] float operator[] (size_t index); + [[nodiscard]] float operator[] (int index) const; + [[nodiscard]] float operator[] (size_t index) const; /*---------------------------------------------------------------------------------*/ /* Function Members */ /*---------------------------------------------------------------------------------*/ - [[nodiscard]] float Length () const noexcept; - [[nodiscard]] float LengthSquared () const noexcept; - [[nodiscard]] std::string ToString () const noexcept; + [[nodiscard]] float Length () const noexcept; + [[nodiscard]] float LengthSquared () const noexcept; + [[nodiscard]] std::string ToString () const noexcept; - [[nodiscard]] float Dot (const SHVec2& rhs) const noexcept; - [[nodiscard]] SHVec2 Cross (const SHVec2& rhs) const noexcept; + [[nodiscard]] float Dot (const SHVec2& rhs) const noexcept; + [[nodiscard]] SHVec2 Cross (const SHVec2& rhs) const noexcept; /*---------------------------------------------------------------------------------*/ /* Static Function Members */ /*---------------------------------------------------------------------------------*/ @@ -117,6 +121,6 @@ namespace SHADE [[nodiscard]] static float Cross (const SHVec2& lhs, const SHVec2& rhs) noexcept; }; - SHVec2 operator* (float lhs, const SHVec2& rhs) noexcept; + SHVec2 operator* (float lhs, const SHVec2& rhs) noexcept; } // namespace SHADE \ No newline at end of file diff --git a/SHADE_Engine/src/Math/Vector/SHVec3.cpp b/SHADE_Engine/src/Math/Vector/SHVec3.cpp index 73030f9c..194f7964 100644 --- a/SHADE_Engine/src/Math/Vector/SHVec3.cpp +++ b/SHADE_Engine/src/Math/Vector/SHVec3.cpp @@ -43,6 +43,10 @@ namespace SHADE : XMFLOAT3( 0.0f, 0.0f, 0.0f ) {} + SHVec3::SHVec3(float n) noexcept + : XMFLOAT3( n, n, n ) + {} + SHVec3::SHVec3(float _x, float _y, float _z) noexcept : XMFLOAT3( _x, _y, _z ) {} diff --git a/SHADE_Engine/src/Math/Vector/SHVec3.h b/SHADE_Engine/src/Math/Vector/SHVec3.h index e172e824..476d7b0f 100644 --- a/SHADE_Engine/src/Math/Vector/SHVec3.h +++ b/SHADE_Engine/src/Math/Vector/SHVec3.h @@ -14,6 +14,9 @@ #include #include +// Project Headers +#include "SH_API.h" + namespace SHADE { /*-----------------------------------------------------------------------------------*/ @@ -25,7 +28,7 @@ namespace SHADE /* Type Definitions */ /*-----------------------------------------------------------------------------------*/ - class SHVec3 : public DirectX::XMFLOAT3 + class SH_API SHVec3 : public DirectX::XMFLOAT3 { public: /*---------------------------------------------------------------------------------*/ @@ -50,62 +53,63 @@ namespace SHADE /* Constructors & Destructor */ /*---------------------------------------------------------------------------------*/ - SHVec3 (const SHVec3& rhs) = default; - SHVec3 (SHVec3&& rhs) = default; - ~SHVec3 () = default; + SHVec3 (const SHVec3& rhs) = default; + SHVec3 (SHVec3&& rhs) = default; + ~SHVec3 () = default; - SHVec3 () noexcept; - SHVec3 (float x, float y, float z) noexcept; + SHVec3 () noexcept; + SHVec3 (float n) noexcept; + SHVec3 (float x, float y, float z) noexcept; /*---------------------------------------------------------------------------------*/ /* Operator Overloads */ /*---------------------------------------------------------------------------------*/ - [[nodiscard]] SHVec3& operator= (const SHVec3& rhs) = default; - [[nodiscard]] SHVec3& operator= (SHVec3&& rhs) = default; + SHVec3& operator= (const SHVec3& rhs) = default; + SHVec3& operator= (SHVec3&& rhs) = default; - [[nodiscard]] SHVec3& operator+= (const SHVec3& rhs) noexcept; - [[nodiscard]] SHVec3& operator-= (const SHVec3& rhs) noexcept; - [[nodiscard]] SHVec3& operator*= (const SHVec3& rhs) noexcept; - [[nodiscard]] SHVec3& operator*= (float rhs) noexcept; - [[nodiscard]] SHVec3& operator/= (const SHVec3& rhs) noexcept; - [[nodiscard]] SHVec3& operator/= (float rhs) noexcept; + SHVec3& operator+= (const SHVec3& rhs) noexcept; + SHVec3& operator-= (const SHVec3& rhs) noexcept; + SHVec3& operator*= (const SHVec3& rhs) noexcept; + SHVec3& operator*= (float rhs) noexcept; + SHVec3& operator/= (const SHVec3& rhs) noexcept; + SHVec3& operator/= (float rhs) noexcept; - [[nodiscard]] SHVec3 operator+ (const SHVec3& rhs) const noexcept; - [[nodiscard]] SHVec3 operator- (const SHVec3& rhs) const noexcept; - [[nodiscard]] SHVec3 operator- () const noexcept; - [[nodiscard]] SHVec3 operator* (const SHVec3& rhs) const noexcept; - [[nodiscard]] SHVec3 operator* (float rhs) const noexcept; - [[nodiscard]] SHVec3 operator/ (const SHVec3& rhs) const noexcept; - [[nodiscard]] SHVec3 operator/ (float rhs) const noexcept; + [[nodiscard]] SHVec3 operator+ (const SHVec3& rhs) const noexcept; + [[nodiscard]] SHVec3 operator- (const SHVec3& rhs) const noexcept; + [[nodiscard]] SHVec3 operator- () const noexcept; + [[nodiscard]] SHVec3 operator* (const SHVec3& rhs) const noexcept; + [[nodiscard]] SHVec3 operator* (float rhs) const noexcept; + [[nodiscard]] SHVec3 operator/ (const SHVec3& rhs) const noexcept; + [[nodiscard]] SHVec3 operator/ (float rhs) const noexcept; - [[nodiscard]] bool operator== (const SHVec3& rhs) const noexcept; - [[nodiscard]] bool operator!= (const SHVec3& rhs) const noexcept; + [[nodiscard]] bool operator== (const SHVec3& rhs) const noexcept; + [[nodiscard]] bool operator!= (const SHVec3& rhs) const noexcept; - [[nodiscard]] float operator[] (int index); - [[nodiscard]] float operator[] (size_t index); - [[nodiscard]] float operator[] (int index) const; - [[nodiscard]] float operator[] (size_t index) const; + [[nodiscard]] float operator[] (int index); + [[nodiscard]] float operator[] (size_t index); + [[nodiscard]] float operator[] (int index) const; + [[nodiscard]] float operator[] (size_t index) const; /*---------------------------------------------------------------------------------*/ /* Function Members */ /*---------------------------------------------------------------------------------*/ - [[nodiscard]] float Length () const noexcept; - [[nodiscard]] float LengthSquared () const noexcept; - [[nodiscard]] std::string ToString () const noexcept; + [[nodiscard]] float Length () const noexcept; + [[nodiscard]] float LengthSquared () const noexcept; + [[nodiscard]] std::string ToString () const noexcept; - [[nodiscard]] float Dot (const SHVec3& rhs) const noexcept; - [[nodiscard]] SHVec3 Cross (const SHVec3& rhs) const noexcept; + [[nodiscard]] float Dot (const SHVec3& rhs) const noexcept; + [[nodiscard]] SHVec3 Cross (const SHVec3& rhs) const noexcept; /*---------------------------------------------------------------------------------*/ /* Static Function Members */ /*---------------------------------------------------------------------------------*/ - [[nodiscard]] static SHVec3 Normalise (const SHVec3& v) noexcept; - [[nodiscard]] static SHVec3 Abs (const SHVec3& v) noexcept; - [[nodiscard]] static SHVec3 Min (const std::initializer_list& vs) noexcept; - [[nodiscard]] static SHVec3 Max (const std::initializer_list& vs) noexcept; + [[nodiscard]] static SHVec3 Normalise (const SHVec3& v) noexcept; + [[nodiscard]] static SHVec3 Abs (const SHVec3& v) noexcept; + [[nodiscard]] static SHVec3 Min (const std::initializer_list& vs) noexcept; + [[nodiscard]] static SHVec3 Max (const std::initializer_list& vs) noexcept; [[nodiscard]] static SHVec3 Clamp (const SHVec3& v, const SHVec3& vMin, const SHVec3& vMax) noexcept; [[nodiscard]] static SHVec3 Lerp (const SHVec3& a, const SHVec3& b, float t) noexcept; [[nodiscard]] static SHVec3 ClampedLerp (const SHVec3& a, const SHVec3& b, float t, float tMin = 0.0f, float tMax = 1.0f) noexcept; @@ -124,6 +128,6 @@ namespace SHADE [[nodiscard]] static SHVec3 Transform (const SHVec3& v, const SHMatrix& transformMtx) noexcept; }; - SHVec3 operator* (float lhs, const SHVec3& rhs) noexcept; + SHVec3 operator* (float lhs, const SHVec3& rhs) noexcept; } // namespace SHADE \ No newline at end of file diff --git a/SHADE_Engine/src/Math/Vector/SHVec4.h b/SHADE_Engine/src/Math/Vector/SHVec4.h index c4caf2c8..a4a5208a 100644 --- a/SHADE_Engine/src/Math/Vector/SHVec4.h +++ b/SHADE_Engine/src/Math/Vector/SHVec4.h @@ -14,6 +14,9 @@ #include #include +// Project Headers +#include "SH_API.h" + namespace SHADE { /*-----------------------------------------------------------------------------------*/ @@ -25,7 +28,7 @@ namespace SHADE /* Type Definitions */ /*-----------------------------------------------------------------------------------*/ - class SHVec4 : public DirectX::XMFLOAT4 + class SH_API SHVec4 : public DirectX::XMFLOAT4 { public: /*---------------------------------------------------------------------------------*/ @@ -45,57 +48,57 @@ namespace SHADE /* Constructors & Destructor */ /*---------------------------------------------------------------------------------*/ - SHVec4 (const SHVec4& rhs) = default; - SHVec4 (SHVec4&& rhs) = default; - ~SHVec4 () = default; + SHVec4 (const SHVec4& rhs) = default; + SHVec4 (SHVec4&& rhs) = default; + ~SHVec4 () = default; - SHVec4 () noexcept; - SHVec4 (float x, float y, float z, float w) noexcept; + SHVec4 () noexcept; + SHVec4 (float x, float y, float z, float w) noexcept; /*---------------------------------------------------------------------------------*/ /* Operator Overloads */ /*---------------------------------------------------------------------------------*/ - [[nodiscard]] SHVec4& operator= (const SHVec4& rhs) = default; - [[nodiscard]] SHVec4& operator= (SHVec4&& rhs) = default; - - [[nodiscard]] SHVec4& operator+= (const SHVec4& rhs) noexcept; - [[nodiscard]] SHVec4& operator-= (const SHVec4& rhs) noexcept; - [[nodiscard]] SHVec4& operator*= (const SHVec4& rhs) noexcept; - [[nodiscard]] SHVec4& operator*= (float rhs) noexcept; - [[nodiscard]] SHVec4& operator/= (const SHVec4& rhs) noexcept; - [[nodiscard]] SHVec4& operator/= (float rhs) noexcept; + SHVec4& operator= (const SHVec4& rhs) = default; + SHVec4& operator= (SHVec4&& rhs) = default; - [[nodiscard]] SHVec4 operator+ (const SHVec4& rhs) const noexcept; - [[nodiscard]] SHVec4 operator- (const SHVec4& rhs) const noexcept; - [[nodiscard]] SHVec4 operator- () const noexcept; - [[nodiscard]] SHVec4 operator* (const SHVec4& rhs) const noexcept; - [[nodiscard]] SHVec4 operator* (float rhs) const noexcept; - [[nodiscard]] SHVec4 operator/ (const SHVec4& rhs) const noexcept; - [[nodiscard]] SHVec4 operator/ (float rhs) const noexcept; + SHVec4& operator+= (const SHVec4& rhs) noexcept; + SHVec4& operator-= (const SHVec4& rhs) noexcept; + SHVec4& operator*= (const SHVec4& rhs) noexcept; + SHVec4& operator*= (float rhs) noexcept; + SHVec4& operator/= (const SHVec4& rhs) noexcept; + SHVec4& operator/= (float rhs) noexcept; - [[nodiscard]] bool operator== (const SHVec4& rhs) const noexcept; - [[nodiscard]] bool operator!= (const SHVec4& rhs) const noexcept; + [[nodiscard]] SHVec4 operator+ (const SHVec4& rhs) const noexcept; + [[nodiscard]] SHVec4 operator- (const SHVec4& rhs) const noexcept; + [[nodiscard]] SHVec4 operator- () const noexcept; + [[nodiscard]] SHVec4 operator* (const SHVec4& rhs) const noexcept; + [[nodiscard]] SHVec4 operator* (float rhs) const noexcept; + [[nodiscard]] SHVec4 operator/ (const SHVec4& rhs) const noexcept; + [[nodiscard]] SHVec4 operator/ (float rhs) const noexcept; - [[nodiscard]] float operator[] (int index); - [[nodiscard]] float operator[] (size_t index); - [[nodiscard]] float operator[] (int index) const; - [[nodiscard]] float operator[] (size_t index) const; + [[nodiscard]] bool operator== (const SHVec4& rhs) const noexcept; + [[nodiscard]] bool operator!= (const SHVec4& rhs) const noexcept; + + [[nodiscard]] float operator[] (int index); + [[nodiscard]] float operator[] (size_t index); + [[nodiscard]] float operator[] (int index) const; + [[nodiscard]] float operator[] (size_t index) const; /*---------------------------------------------------------------------------------*/ /* Function Members */ /*---------------------------------------------------------------------------------*/ - [[nodiscard]] float Length () const noexcept; - [[nodiscard]] float Length3D () const noexcept; - [[nodiscard]] float LengthSquared () const noexcept; - [[nodiscard]] float LengthSquared3D () const noexcept; - [[nodiscard]] std::string ToString () const noexcept; + [[nodiscard]] float Length () const noexcept; + [[nodiscard]] float Length3D () const noexcept; + [[nodiscard]] float LengthSquared () const noexcept; + [[nodiscard]] float LengthSquared3D () const noexcept; + [[nodiscard]] std::string ToString () const noexcept; - [[nodiscard]] float Dot (const SHVec4& rhs) const noexcept; - [[nodiscard]] float Dot3D (const SHVec4& rhs) const noexcept; - [[nodiscard]] SHVec4 Cross3D (const SHVec4& rhs) const noexcept; - [[nodiscard]] SHVec4 Cross (const SHVec4& v1, const SHVec4& v2) const noexcept; + [[nodiscard]] float Dot (const SHVec4& rhs) const noexcept; + [[nodiscard]] float Dot3D (const SHVec4& rhs) const noexcept; + [[nodiscard]] SHVec4 Cross3D (const SHVec4& rhs) const noexcept; + [[nodiscard]] SHVec4 Cross (const SHVec4& v1, const SHVec4& v2) const noexcept; /*---------------------------------------------------------------------------------*/ /* Static Function Members */ @@ -128,6 +131,6 @@ namespace SHADE }; - SHVec4 operator* (float lhs, const SHVec4& rhs) noexcept; + SHVec4 operator* (float lhs, const SHVec4& rhs) noexcept; } // namespace SHADE \ No newline at end of file diff --git a/SHADE_Engine/src/SHpch.h b/SHADE_Engine/src/SHpch.h index 018113f0..8b2f11f3 100644 --- a/SHADE_Engine/src/SHpch.h +++ b/SHADE_Engine/src/SHpch.h @@ -9,7 +9,10 @@ #pragma once + + #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +#define NOMINMAX // Windows Header Files #include // C RunTime Header Files @@ -34,3 +37,4 @@ #include #include "Common/SHCommonTypes.h" +#include "Tools/SHLogger.h" diff --git a/SHADE_Engine/src/Scene/SHSceneManager.h b/SHADE_Engine/src/Scene/SHSceneManager.h index 9682e4c2..6ce90042 100644 --- a/SHADE_Engine/src/Scene/SHSceneManager.h +++ b/SHADE_Engine/src/Scene/SHSceneManager.h @@ -13,11 +13,15 @@ #define SH_SCENE_MANAGER_H -#include "ECS_Base/General/SHFamily.h" + #include "SHScene.h" #include #include "SH_API.h" +//Project Headers +#include "SH_API.h" +#include "ECS_Base/General/SHFamily.h" + namespace SHADE { diff --git a/SHADE_Engine/src/Tools/SHLogger.h b/SHADE_Engine/src/Tools/SHLogger.h index b2c01b73..e4a4928c 100644 --- a/SHADE_Engine/src/Tools/SHLogger.h +++ b/SHADE_Engine/src/Tools/SHLogger.h @@ -74,33 +74,33 @@ namespace SHADE /* Getter Functions */ /*---------------------------------------------------------------------------------*/ - [[nodiscard]] static const std::string& GetTrivialPattern () noexcept { return trivialPattern; } - [[nodiscard]] static const std::string& GetVerbosePattern () noexcept { return verbosePattern; } + [[nodiscard]] static const std::string& GetTrivialPattern () noexcept { return trivialPattern; } + [[nodiscard]] static const std::string& GetVerbosePattern () noexcept { return verbosePattern; } /*---------------------------------------------------------------------------------*/ /* Setter Functions */ /*---------------------------------------------------------------------------------*/ - static void SetTrivialPattern (const std::string& pattern) noexcept { trivialPattern = pattern; } - static void SetVerbosePattern (const std::string& pattern) noexcept { verbosePattern = pattern; } + static void SetTrivialPattern (const std::string& pattern) noexcept { trivialPattern = pattern; } + static void SetVerbosePattern (const std::string& pattern) noexcept { verbosePattern = pattern; } - static void SetConfig (const Config& config) noexcept; + static void SetConfig (const Config& config) noexcept; - static void SetShowTime (bool showTime) noexcept; - static void SetShowDate (bool showDate) noexcept; - static void SetShowFunctionFileName (bool showFunctionFileName) noexcept; - static void SetShowFunctionLineNumber (bool showFunctionLineNumber) noexcept; + static void SetShowTime (bool showTime) noexcept; + static void SetShowDate (bool showDate) noexcept; + static void SetShowFunctionFileName (bool showFunctionFileName) noexcept; + static void SetShowFunctionLineNumber (bool showFunctionLineNumber) noexcept; - static void SetClockFormat (ClockFormat newClockFormat) noexcept; - static void SetDateFormat (DateFormat newDateFormat) noexcept; + static void SetClockFormat (ClockFormat newClockFormat) noexcept; + static void SetDateFormat (DateFormat newDateFormat) noexcept; - static void SetFileName (const std::string& logFileName) noexcept; - static void SetDirectoryPath (const std::filesystem::path& logDirectoryPath) noexcept; + static void SetFileName (const std::string& logFileName) noexcept; + static void SetDirectoryPath (const std::filesystem::path& logDirectoryPath) noexcept; - static void SetFlushTime (int seconds) noexcept; - static void SetFlushTime (size_t seconds) noexcept { spdlog::flush_every(std::chrono::seconds(seconds)); } + static void SetFlushTime (int seconds) noexcept; + static void SetFlushTime (size_t seconds) noexcept { spdlog::flush_every(std::chrono::seconds(seconds)); } /*---------------------------------------------------------------------------------*/ /* Function Members */