diff --git a/tempest/Vector.hpp b/tempest/Vector.hpp index c99d63f..163a555 100644 --- a/tempest/Vector.hpp +++ b/tempest/Vector.hpp @@ -5,5 +5,6 @@ #include "tempest/vector/C2iVector.hpp" #include "tempest/vector/C3Vector.hpp" #include "tempest/vector/C4Vector.hpp" +#include "tempest/vector/CImVector.hpp" #endif diff --git a/tempest/vector/CImVector.cpp b/tempest/vector/CImVector.cpp new file mode 100644 index 0000000..2f41467 --- /dev/null +++ b/tempest/vector/CImVector.cpp @@ -0,0 +1,19 @@ +#include "tempest/vector/CImVector.hpp" +#include "tempest/Math.hpp" + +uint32_t CImVector::MakeARGB(uint8_t a, uint8_t r, uint8_t g, uint8_t b) { + return a << 24 | r << 16 | g << 8 | b; +} + +bool CImVector::operator==(const CImVector& color) { + return this->value == color.value; +} + +void CImVector::Set(float a, float r, float g, float b) { + uint8_t a_ = CMath::fuint_n(a * 255.0f); + uint8_t r_ = CMath::fuint_n(r * 255.0f); + uint8_t g_ = CMath::fuint_n(g * 255.0f); + uint8_t b_ = CMath::fuint_n(b * 255.0f); + + this->value = CImVector::MakeARGB(a_, r_, g_, b_); +} diff --git a/tempest/vector/CImVector.hpp b/tempest/vector/CImVector.hpp new file mode 100644 index 0000000..fce52ab --- /dev/null +++ b/tempest/vector/CImVector.hpp @@ -0,0 +1,28 @@ +#ifndef TEMPEST_VECTOR_C_IMVECTOR_HPP +#define TEMPEST_VECTOR_C_IMVECTOR_HPP + +#include + +class CImVector { + public: + // Static functions + static uint32_t MakeARGB(uint8_t a, uint8_t r, uint8_t g, uint8_t b); + + // Member variables + union { + struct { + uint8_t b; + uint8_t g; + uint8_t r; + uint8_t a; + }; + + uint32_t value; + }; + + // Member functions + bool operator==(const CImVector& color); + void Set(float a, float r, float g, float b); +}; + +#endif