Initial commit
This commit is contained in:
commit
edfc5298e1
252 changed files with 93965 additions and 0 deletions
128
source/Math/Color.cpp
Normal file
128
source/Math/Color.cpp
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
|
||||
#include <Spectre/Math/Color.h>
|
||||
|
||||
const Color Color::Black (0 , 0 , 0 , 255);
|
||||
const Color Color::White (255, 255, 255, 255);
|
||||
const Color Color::Red (255, 0 , 0 , 255);
|
||||
const Color Color::Green (0 , 255, 0 , 255);
|
||||
const Color Color::Blue (0 , 0 , 255, 255);
|
||||
const Color Color::Transparant (0 , 0 , 0 , 0 );
|
||||
|
||||
Color::Color(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha)
|
||||
{
|
||||
r = red; g = green; b = blue; a = alpha;
|
||||
}
|
||||
|
||||
Color::Color(const Color& color)
|
||||
{
|
||||
r = color.r; g = color.g; b = color.b; a = color.a;
|
||||
}
|
||||
|
||||
Color& Color::operator=(const Color& color)
|
||||
{
|
||||
if (*this != color) {
|
||||
r = color.r;
|
||||
g = color.g;
|
||||
b = color.b;
|
||||
a = color.a;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vector3f Color::toRGBf() const
|
||||
{
|
||||
Vector3f v(r, g, b);
|
||||
return v / 255.0f;
|
||||
}
|
||||
|
||||
Vector4f Color::toRGBAf() const
|
||||
{
|
||||
Vector4f v(r, g, b, a);
|
||||
return v / 255.0f;
|
||||
}
|
||||
|
||||
// ---------
|
||||
// Compare
|
||||
// ---------
|
||||
|
||||
bool operator ==(const Color& c1, const Color& c2)
|
||||
{
|
||||
return c1.r == c2.r && c1.g == c2.g && c1.b == c2.b && c1.a == c2.b;
|
||||
}
|
||||
|
||||
bool operator !=(const Color& c1, const Color& c2)
|
||||
{
|
||||
return !(c1.r == c2.r && c1.g == c2.g && c1.b == c2.b && c1.a == c2.b);
|
||||
}
|
||||
|
||||
// ------------
|
||||
// Arithmetic
|
||||
// ------------
|
||||
|
||||
Color operator +(const Color& c1, const Color& c2)
|
||||
{
|
||||
return Color(c1.r + c2.r, c1.g + c2.g, c1.b + c2.b, c1.a + c2.a);
|
||||
}
|
||||
|
||||
Color operator -(const Color& c1, const Color& c2)
|
||||
{
|
||||
return Color(c1.r - c2.r, c1.g - c2.g, c1.b - c2.b, c1.a - c2.a);
|
||||
}
|
||||
|
||||
Color operator /(const Color& c1, const Color& c2)
|
||||
{
|
||||
return Color(c1.r / c2.r, c1.g / c2.g, c1.b / c2.b, c1.a / c2.a);
|
||||
}
|
||||
|
||||
Color operator *(const Color& c1, const Color& c2)
|
||||
{
|
||||
return Color(c1.r * c2.r, c1.g * c2.g, c1.b * c2.b, c1.a * c2.a);
|
||||
}
|
||||
|
||||
Color& operator +=(Color& c1, const Color& c2)
|
||||
{
|
||||
c1.r += c2.r; c1.g += c2.g; c1.b += c2.b; c1.a += c2.a;
|
||||
return c1;
|
||||
}
|
||||
|
||||
Color& operator -=(Color& c1, const Color& c2)
|
||||
{
|
||||
c1.r -= c2.r; c1.g -= c2.g; c1.b -= c2.b; c1.a -= c2.a;
|
||||
return c1;
|
||||
}
|
||||
|
||||
Color& operator /=(Color& c1, const Color& c2)
|
||||
{
|
||||
c1.r /= c2.r; c1.g /= c2.g; c1.b /= c2.b; c1.a /= c2.a;
|
||||
return c1;
|
||||
}
|
||||
|
||||
Color& operator *=(Color& c1, const Color& c2)
|
||||
{
|
||||
c1.r *= c2.r; c1.g *= c2.g; c1.b *= c2.b; c1.a *= c2.a;
|
||||
return c1;
|
||||
}
|
||||
|
||||
// -------------------
|
||||
// Scalar arithmetic
|
||||
// -------------------
|
||||
|
||||
Color operator +(const Color& c, unsigned int s)
|
||||
{
|
||||
return Color(c.r + s, c.g + s, c.b + s, c.a + s);
|
||||
}
|
||||
|
||||
Color operator -(const Color& c, unsigned int s)
|
||||
{
|
||||
return Color(c.r - s, c.g - s, c.b - s, c.a - s);
|
||||
}
|
||||
|
||||
Color operator /(const Color& c, unsigned int s)
|
||||
{
|
||||
return Color(c.r / s, c.g / s, c.b / s, c.a / s);
|
||||
}
|
||||
|
||||
Color operator *(const Color& c, unsigned int s)
|
||||
{
|
||||
return Color(c.r * s, c.g * s, c.b * s, c.a * s);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue