fart/util/Color.cc
Josh Holtrop 57a4e6ed8a trying new jitter method for soft shadows, getting better
git-svn-id: svn://anubis/fart/trunk@257 7f9b0f55-74a9-4bce-be96-3c2cd072584d
2010-07-13 06:35:45 +00:00

121 lines
2.2 KiB
C++

#include "Color.h"
const Color Color::black = Color(0, 0, 0);
const Color Color::white = Color(1, 1, 1);
const Color Color::red = Color(1, 0, 0);
const Color Color::green = Color(0, 1, 0);
const Color Color::blue = Color(0, 0, 1);
const Color Color::yellow = Color(1, 1, 0);
const Color Color::cyan = Color(0, 1, 1);
const Color Color::magenta = Color(1, 0, 1);
Color::Color()
{
r = g = b = 0.0;
}
Color::Color(double r, double g, double b)
{
this->r = r;
this->g = g;
this->b = b;
}
Color::Color(const Vector & v)
{
r = v[0];
g = v[1];
b = v[2];
}
Color::Color(refptr<Vector> v)
{
r = (*v)[0];
g = (*v)[1];
b = (*v)[2];
}
Color Color::operator*(const Color & other) const
{
Color result;
result.r = r * other.r;
result.g = g * other.g;
result.b = b * other.b;
return result;
}
Color Color::operator*(double scale) const
{
return Color(r * scale, g * scale, b * scale);
}
Color Color::operator/(double scale) const
{
return Color(r / scale, g / scale, b / scale);
}
Color & Color::operator+=(const Color & other)
{
r += other.r;
g += other.g;
b += other.b;
return *this;
}
Color & Color::operator-=(const Color & other)
{
r += other.r;
g += other.g;
b += other.b;
return *this;
}
Color & Color::operator*=(double scale)
{
r *= scale;
g *= scale;
b *= scale;
return *this;
}
Color & Color::operator*=(const Color & other)
{
r *= other.r;
g *= other.g;
b *= other.b;
return *this;
}
Color & Color::operator/=(double scale)
{
r /= scale;
g /= scale;
b /= scale;
return *this;
}
Color & Color::operator/=(const Color & other)
{
r /= other.r;
g /= other.g;
b /= other.b;
return *this;
}
Color operator+(const Color & c1, const Color & c2)
{
return Color(c1.r + c2.r, c1.g + c2.g, c1.b + c2.b);
}
Color operator-(const Color & c1, const Color & c2)
{
return Color(c1.r - c2.r, c1.g - c2.g, c1.b - c2.b);
}
std::ostream & operator<<(std::ostream & out, const Color & color)
{
out << "[" << color.r << ", " << color.g << ", " << color.b << "]";
return out;
}