From f1e6031d2e664348fe4f589bf5719d4db42f07c9 Mon Sep 17 00:00:00 2001 From: Cocoa Date: Mon, 19 Sep 2022 14:32:01 +0800 Subject: [PATCH] Added Transform, adjusted alignment in math files for better readability on smaller screens --- SHADE_Application/SHADE_Application.vcxproj | 2 +- .../src/Application/SBApplication.cpp | 10 +- SHADE_Engine/SHADE_Engine.vcxproj | 5 +- SHADE_Engine/SHADE_Engine.vcxproj.filters | 7 + SHADE_Engine/src/Math/SHMath.h | 5 +- SHADE_Engine/src/Math/SHMathHelpers.h | 22 +-- SHADE_Engine/src/Math/SHMathHelpers.hpp | 24 +++- SHADE_Engine/src/Math/SHMatrix.cpp | 19 --- SHADE_Engine/src/Math/SHMatrix.h | 129 +++++++++--------- SHADE_Engine/src/Math/SHQuaternion.cpp | 30 +++- SHADE_Engine/src/Math/SHQuaternion.h | 84 ++++++------ SHADE_Engine/src/Math/SHTransform.cpp | 60 ++++++++ SHADE_Engine/src/Math/SHTransform.h | 64 +++++++++ SHADE_Engine/src/Math/Vector/SHVec2.h | 64 ++++----- SHADE_Engine/src/Math/Vector/SHVec3.h | 72 +++++----- SHADE_Engine/src/Math/Vector/SHVec4.h | 74 +++++----- SHADE_Engine/src/SHpch.h | 5 + SHADE_Engine/src/Tools/SHLogger.h | 30 ++-- 18 files changed, 445 insertions(+), 261 deletions(-) create mode 100644 SHADE_Engine/src/Math/SHTransform.cpp create mode 100644 SHADE_Engine/src/Math/SHTransform.h diff --git a/SHADE_Application/SHADE_Application.vcxproj b/SHADE_Application/SHADE_Application.vcxproj index 2616224e..9a566252 100644 --- a/SHADE_Application/SHADE_Application.vcxproj +++ b/SHADE_Application/SHADE_Application.vcxproj @@ -66,7 +66,7 @@ false MultiThreadedDebugDLL true - stdcpplatest + stdcpp20 Windows diff --git a/SHADE_Application/src/Application/SBApplication.cpp b/SHADE_Application/src/Application/SBApplication.cpp index 184b9611..4ff1a0c2 100644 --- a/SHADE_Application/src/Application/SBApplication.cpp +++ b/SHADE_Application/src/Application/SBApplication.cpp @@ -6,6 +6,9 @@ #include "Scenes/SBEditorScene.h" #endif // SHEDITOR +#include "Math/SHMath.h" +#include "Tools/SHLogger.h" + #include #include #include @@ -17,11 +20,14 @@ namespace Sandbox ( _In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, - _In_ LPWSTR lpCmdLine, + _In_ LPWSTR lpCmdLine, _In_ INT nCmdShow ) { - + + SHADE::SHQuaternion aroundZ20{ SHADE::SHVec3::UnitZ, SHADE::SHMath::DegreesToRadians(20.0f) }; + SHLOG_INFO("Angle is {}", SHADE::SHMath::RadiansToDegrees(aroundZ20.GetAngle())) + window.Create(hInstance, hPrevInstance, lpCmdLine, nCmdShow); #ifdef SHEDITOR diff --git a/SHADE_Engine/SHADE_Engine.vcxproj b/SHADE_Engine/SHADE_Engine.vcxproj index 1c50ecc0..60a09861 100644 --- a/SHADE_Engine/SHADE_Engine.vcxproj +++ b/SHADE_Engine/SHADE_Engine.vcxproj @@ -64,7 +64,7 @@ false MultiThreadedDebugDLL true - stdcpplatest + stdcpp20 Windows @@ -174,8 +174,10 @@ + + @@ -250,6 +252,7 @@ + diff --git a/SHADE_Engine/SHADE_Engine.vcxproj.filters b/SHADE_Engine/SHADE_Engine.vcxproj.filters index 7486fad4..42084b70 100644 --- a/SHADE_Engine/SHADE_Engine.vcxproj.filters +++ b/SHADE_Engine/SHADE_Engine.vcxproj.filters @@ -339,6 +339,9 @@ Math + + Math + Math\Vector @@ -382,6 +385,7 @@ Tools + @@ -555,6 +559,9 @@ Math + + Math + Math\Vector 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..1580ce47 100644 --- a/SHADE_Engine/src/Math/SHMathHelpers.h +++ b/SHADE_Engine/src/Math/SHMathHelpers.h @@ -56,25 +56,31 @@ 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 Max (T lhs, T rhs); template - [[nodiscard]] static T Lerp (T a, T b, T alpha); + [[nodiscard]] static T DegreesToRadians (T angleInDeg); template - [[nodiscard]] static T ClampedLerp (T a, T b, T alpha, T alphaMin, T alphaMax); + [[nodiscard]] static T RadiansToDegrees (T angleInRad); template - [[nodiscard]] static T Wrap (T value, T min, T max); + [[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 +92,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..4b49a9a5 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,25 @@ namespace SHADE /*-----------------------------------------------------------------------------------*/ template - constexpr T SHMath::DegreesToRadians(T angleInDeg) + T SHMath::Min(T lhs, T rhs) + { + return lhs < rhs ? lhs : rhs; + } + + template + T SHMath::Max(T lhs, T rhs) + { + return lhs > rhs ? lhs : rhs; + } + + 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 +91,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 2aab05ab..f5d7c173 100644 --- a/SHADE_Engine/src/Math/SHMatrix.h +++ b/SHADE_Engine/src/Math/SHMatrix.h @@ -49,96 +49,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..820392fa 100644 --- a/SHADE_Engine/src/Math/SHQuaternion.h +++ b/SHADE_Engine/src/Math/SHQuaternion.h @@ -20,6 +20,7 @@ namespace SHADE /*-----------------------------------------------------------------------------------*/ class SHVec3; + class SHVec4; class SHMatrix; /*-----------------------------------------------------------------------------------*/ @@ -39,68 +40,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/SHTransform.cpp b/SHADE_Engine/src/Math/SHTransform.cpp new file mode 100644 index 00000000..757ac5b6 --- /dev/null +++ b/SHADE_Engine/src/Math/SHTransform.cpp @@ -0,0 +1,60 @@ +/**************************************************************************************** + * \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 +{ + /*-----------------------------------------------------------------------------------*/ + /* Stai Definitions */ + /*-----------------------------------------------------------------------------------*/ + + + + /*-----------------------------------------------------------------------------------*/ + /* Constructors & Destructor Definitions */ + /*-----------------------------------------------------------------------------------*/ + + SHTransform::SHTransform() noexcept + : position { SHVec3::Zero } + , rotation { SHVec3::Zero } + , scale { SHVec3::One } + {} + + /*-----------------------------------------------------------------------------------*/ + /* Getter Function Definitions */ + /*-----------------------------------------------------------------------------------*/ + + const SHMatrix& SHTransform::GetTRS() const + { + return trs; + } + + + /*-----------------------------------------------------------------------------------*/ + /* 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/SHTransform.h b/SHADE_Engine/src/Math/SHTransform.h new file mode 100644 index 00000000..a6d9a1b2 --- /dev/null +++ b/SHADE_Engine/src/Math/SHTransform.h @@ -0,0 +1,64 @@ +/**************************************************************************************** + * \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 + +#include "SHMath.h" + +namespace SHADE +{ + /*-----------------------------------------------------------------------------------*/ + /* Type Definitions */ + /*-----------------------------------------------------------------------------------*/ + + struct SHTransform + { + public: + /*---------------------------------------------------------------------------------*/ + /* Data Members */ + /*---------------------------------------------------------------------------------*/ + + static const SHTransform Identity; + + SHVec3 position; + SHVec3 rotation; + SHVec3 scale; + + /*---------------------------------------------------------------------------------*/ + /* Constructors & Destructor */ + /*---------------------------------------------------------------------------------*/ + + SHTransform (const SHTransform&) = default; + SHTransform (SHTransform&&) = default; + + SHTransform& operator= (const SHTransform&) = default; + SHTransform& operator= (SHTransform&&) = default; + + ~SHTransform () = default; + + SHTransform () noexcept; + + /*---------------------------------------------------------------------------------*/ + /* Getter Functions */ + /*---------------------------------------------------------------------------------*/ + + [[nodiscard]] const SHMatrix& GetTRS() const; + + /*---------------------------------------------------------------------------------*/ + /* Function Members */ + /*---------------------------------------------------------------------------------*/ + + const SHMatrix& ComputeTRS(); + + private: + SHMatrix trs; + }; + +} // namespace SHADE \ No newline at end of file diff --git a/SHADE_Engine/src/Math/Vector/SHVec2.h b/SHADE_Engine/src/Math/Vector/SHVec2.h index a64d4bb0..0b272b40 100644 --- a/SHADE_Engine/src/Math/Vector/SHVec2.h +++ b/SHADE_Engine/src/Math/Vector/SHVec2.h @@ -45,53 +45,53 @@ 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 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 +117,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.h b/SHADE_Engine/src/Math/Vector/SHVec3.h index e172e824..059c5708 100644 --- a/SHADE_Engine/src/Math/Vector/SHVec3.h +++ b/SHADE_Engine/src/Math/Vector/SHVec3.h @@ -50,62 +50,62 @@ 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 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 +124,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..36793fe0 100644 --- a/SHADE_Engine/src/Math/Vector/SHVec4.h +++ b/SHADE_Engine/src/Math/Vector/SHVec4.h @@ -45,57 +45,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 +128,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 0342eedb..1adf7af3 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 @@ -30,3 +33,5 @@ #include #include #include + +#include "Tools/SHLogger.h" diff --git a/SHADE_Engine/src/Tools/SHLogger.h b/SHADE_Engine/src/Tools/SHLogger.h index ac5f9308..2ba4abaf 100644 --- a/SHADE_Engine/src/Tools/SHLogger.h +++ b/SHADE_Engine/src/Tools/SHLogger.h @@ -70,33 +70,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 */