SP3-16 Slight rework to SHColour for compatibility #159

Merged
direnbharwani merged 7 commits from SP3-16-Math into main 2022-11-02 02:29:07 +08:00
6 changed files with 206 additions and 24 deletions
Showing only changes of commit b9ada6a5be - Show all commits

View File

@ -16,6 +16,7 @@
#include "Assets/SHAssetManager.h"
#include "Camera/SHCameraComponent.h"
#include "Math/SHColour.h"
#include "Resource/SHResourceManager.h"
using namespace SHADE;
@ -159,7 +160,7 @@ namespace Sandbox
SHComponentManager::RemoveComponent <SHColliderComponent>(0);
auto ambientLight = SHEntityManager::CreateEntity<SHLightComponent>();
SHComponentManager::GetComponent<SHLightComponent>(ambientLight)->SetColor(SHVec4(1.0f, 1.0f, 1.0f, 1.0f));
SHComponentManager::GetComponent<SHLightComponent>(ambientLight)->SetColor(SHColour::WHITE);
SHComponentManager::GetComponent<SHLightComponent>(ambientLight)->SetStrength(0.25f);
SHComponentManager::GetComponent<SHLightComponent>(ambientLight)->SetType(SH_LIGHT_TYPE::AMBIENT);
}

View File

@ -87,19 +87,19 @@ namespace SHADE
/*-----------------------------------------------------------------------------------*/
SHColour::SHColour() noexcept
: SHVec4 { 0.0f, 0.0f, 0.0f, 1.0f }
: XMFLOAT4 { 0.0f, 0.0f, 0.0f, 1.0f }
{}
SHColour::SHColour(float r, float g, float b) noexcept
: SHVec4 { r, g, b, 1.0f }
: XMFLOAT4 { r, g, b, 1.0f }
{}
SHColour::SHColour(float r, float g, float b, float a) noexcept
: SHVec4 { r, g, b, a }
: XMFLOAT4 { r, g, b, a }
{}
SHColour::SHColour(uint8_t r, uint8_t g, uint8_t b) noexcept
: SHVec4
: XMFLOAT4
{
static_cast<float>(r) / 255.0f,
static_cast<float>(g) / 255.0f,
@ -109,7 +109,7 @@ namespace SHADE
{}
SHColour::SHColour(uint8_t r, uint8_t g, uint8_t b, uint8_t a) noexcept
: SHVec4
: XMFLOAT4
{
static_cast<float>(r) / 255.0f,
static_cast<float>(g) / 255.0f,
@ -118,12 +118,24 @@ namespace SHADE
}
{}
SHColour::SHColour(const DirectX::XMFLOAT3& colour) noexcept
: SHVec4 { colour.x, colour.y, colour.z, 1.0f }
SHColour::SHColour(const SHVec3& rgb) noexcept
: XMFLOAT4 { rgb.x, rgb.y, rgb.z, 1.0f }
{}
SHColour::SHColour(const SHVec4& rgba) noexcept
: XMFLOAT4 { rgba.x, rgba.y, rgba.z, rgba.w }
{}
SHColour::SHColour(const DirectX::XMFLOAT3& rgb) noexcept
: XMFLOAT4 { rgb.x, rgb.y, rgb.z, 1.0f }
{}
SHColour::SHColour(const DirectX::XMFLOAT4& rgba) noexcept
: XMFLOAT4 { rgba.x, rgba.y, rgba.z, rgba.w }
{}
SHColour::SHColour(const DirectX::XMVECTORF32& colour) noexcept
: SHVec4
: XMFLOAT4
{
XMVectorGetX(colour),
XMVectorGetY(colour),
@ -136,6 +148,86 @@ namespace SHADE
/* Operator Overload Definitions */
/*-----------------------------------------------------------------------------------*/
SHColour::operator XMVECTOR() const noexcept
{
return XMLoadFloat4(this);
}
SHColour::operator SHVec4() const noexcept
{
return SHVec4{ *this };
}
SHColour& SHColour::operator+=(const SHColour& rhs) noexcept
{
return *this = *this + rhs;
}
SHColour& SHColour::operator-=(const SHColour& rhs) noexcept
{
return *this = *this - rhs;
}
SHColour& SHColour::operator*=(const SHColour& rhs) noexcept
{
return *this = *this * rhs;
}
SHColour& SHColour::operator*=(float rhs) noexcept
{
return *this = *this * rhs;
}
SHColour& SHColour::operator/=(const SHColour& rhs) noexcept
{
return *this = *this / rhs;
}
SHColour SHColour::operator+(const SHColour& rhs) const noexcept
{
SHColour result;
XMStoreFloat4(&result, XMVectorAdd(*this, rhs));
return result;
}
SHColour SHColour::operator-(const SHColour& rhs) const noexcept
{
SHColour result;
XMStoreFloat4(&result, XMVectorSubtract(*this, rhs));
return result;
}
SHColour SHColour::operator-() const noexcept
{
return SHColour{ -x, -y, -z, -w };
}
SHColour SHColour::operator*(const SHColour& rhs) const noexcept
{
SHColour result;
XMStoreFloat4(&result, XMVectorMultiply(*this, rhs));
return result;
}
SHColour SHColour::operator*(float rhs) const noexcept
{
SHColour result;
XMStoreFloat4(&result, XMVectorScale(*this, rhs));
return result;
}
SHColour SHColour::operator/(const SHColour& rhs) const noexcept
{
SHColour result;
XMStoreFloat4(&result, XMVectorDivide(*this, rhs));
return result;
}
bool SHColour::operator==(const SHColour& rhs) const noexcept
{
return XMColorEqual(*this, rhs);
@ -146,6 +238,70 @@ namespace SHADE
return XMColorNotEqual(*this, rhs);
}
float& SHColour::operator[](int index)
{
if (index >= SIZE || index < 0)
throw std::invalid_argument("Index out of range!");
switch (index)
{
case 0: return x;
case 1: return y;
case 2: return z;
case 3: return w;
}
}
float& SHColour::operator[](size_t index)
{
if (index >= SIZE || index < 0)
throw std::invalid_argument("Index out of range!");
switch (index)
{
case 0: return x;
case 1: return y;
case 2: return z;
case 3: return w;
}
}
float SHColour::operator[](int index) const
{
if (index >= SIZE || index < 0)
throw std::invalid_argument("Index out of range!");
switch (index)
{
case 0: return x;
case 1: return y;
case 2: return z;
case 3: return w;
}
}
float SHColour::operator[](size_t index) const
{
if (index >= SIZE || index < 0)
throw std::invalid_argument("Index out of range!");
switch (index)
{
case 0: return x;
case 1: return y;
case 2: return z;
case 3: return w;
}
}
SHColour operator* (float lhs, const SHColour& rhs) noexcept
{
SHColour result;
XMStoreFloat4(&result, XMVectorScale(rhs, lhs));
return result;
}
/*-----------------------------------------------------------------------------------*/
/* Function Member Definitions */
/*-----------------------------------------------------------------------------------*/

View File

@ -19,12 +19,6 @@
namespace SHADE
{
/*-----------------------------------------------------------------------------------*/
/* Forward Declarations */
/*-----------------------------------------------------------------------------------*/
class SHColour;
/*-----------------------------------------------------------------------------------*/
/* Type Definitions */
/*-----------------------------------------------------------------------------------*/
@ -40,7 +34,7 @@ namespace SHADE
float v = 0.0f;
};
class SH_API SHColour : private SHVec4
class SH_API SHColour : public DirectX::XMFLOAT4
{
public:
/*---------------------------------------------------------------------------------*/
@ -53,9 +47,11 @@ namespace SHADE
SHColour (uint8_t r, uint8_t g, uint8_t b) noexcept;
SHColour (uint8_t r, uint8_t g, uint8_t b, uint8_t a) noexcept;
SHColour (const SHVec3& colour) noexcept;
SHColour (const DirectX::XMFLOAT3& colour) noexcept;
SHColour (const DirectX::XMVECTORF32& colour) noexcept;
SHColour (const SHVec3& rgb) noexcept;
SHColour (const SHVec4& rgba) noexcept;
SHColour (const DirectX::XMFLOAT3& rgb) noexcept;
SHColour (const DirectX::XMFLOAT4& rgba) noexcept;
SHColour (const DirectX::XMVECTORF32& rgba) noexcept;
SHColour (const SHColour&) = default;
SHColour (SHColour&&) = default;
@ -66,11 +62,32 @@ namespace SHADE
/* Operator Overloads */
/*---------------------------------------------------------------------------------*/
SHColour& operator= (const SHColour&) = default;
SHColour& operator= (SHColour&&) = default;
SHColour& operator= (const SHColour&) = default;
SHColour& operator= (SHColour&&) = default;
bool operator== (const SHColour& rhs) const noexcept;
bool operator!= (const SHColour& rhs) const noexcept;
operator DirectX::XMVECTOR () const noexcept;
operator SHVec4 () const noexcept;
SHColour& operator+= (const SHColour& rhs) noexcept;
SHColour& operator-= (const SHColour& rhs) noexcept;
SHColour& operator*= (const SHColour& rhs) noexcept;
SHColour& operator*= (float rhs) noexcept;
SHColour& operator/= (const SHColour& rhs) noexcept;
[[nodiscard]] SHColour operator+ (const SHColour& rhs) const noexcept;
[[nodiscard]] SHColour operator- (const SHColour& rhs) const noexcept;
[[nodiscard]] SHColour operator- () const noexcept;
[[nodiscard]] SHColour operator* (const SHColour& rhs) const noexcept;
[[nodiscard]] SHColour operator* (float rhs) const noexcept;
[[nodiscard]] SHColour operator/ (const SHColour& rhs) const noexcept;
[[nodiscard]] bool operator== (const SHColour& rhs) const noexcept;
[[nodiscard]] bool operator!= (const SHColour& 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;
/*---------------------------------------------------------------------------------*/
/* Properties */
@ -105,6 +122,8 @@ namespace SHADE
/* Static Data Members */
/*---------------------------------------------------------------------------------*/
static constexpr size_t SIZE = 4U;
static const SHColour BEIGE ;
static const SHColour BLACK ;
static const SHColour BLUE ;
@ -159,8 +178,9 @@ namespace SHADE
static const SHColour TURQUOISE ;
static const SHColour VIOLET ;
static const SHColour WHITE ;
static const SHColour YELLOW;
static const SHColour YELLOW ;
};
SHColour operator* (float lhs, const SHColour& rhs) noexcept;
} // namespace SHADE

View File

@ -9,4 +9,6 @@
#include "SHQuaternion.h"
#include "SHMatrix.h"
#include "SHColour.h"
#include "Transform/SHTransform.h"

View File

@ -14,6 +14,7 @@
#include "SHVec4.h"
// Project Headers
#include "Math/SHMatrix.h"
#include "Math/SHColour.h"
#include "Tools/SHLogger.h"
using namespace DirectX;

View File

@ -23,7 +23,9 @@ namespace SHADE
/*-----------------------------------------------------------------------------------*/
/* Forward Declarations */
/*-----------------------------------------------------------------------------------*/
class SHMatrix;
class SHColour;
/*-----------------------------------------------------------------------------------*/
/* Type Definitions */