fart/util/Color.h
Josh Holtrop 835a0c968f moved a bunch of functionality from Ray.cc and Color.cc into Ray.h and Color.h
git-svn-id: svn://anubis/fart/trunk@308 7f9b0f55-74a9-4bce-be96-3c2cd072584d
2010-09-28 17:16:39 +00:00

133 lines
2.9 KiB
C++

#ifndef COLOR_H
#define COLOR_H COLOR_H
#include "refptr.h"
#include <iostream>
#include "util/Vector.h"
class Color
{
public:
double r, g, b;
Color()
{
r = g = b = 0.0;
}
Color(double r, double g, double b)
{
this->r = r;
this->g = g;
this->b = b;
}
Color(const Vector & v)
{
r = v[0];
g = v[1];
b = v[2];
}
Color(refptr<Vector> v)
{
r = (*v)[0];
g = (*v)[1];
b = (*v)[2];
}
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 operator*(double scale) const
{
return Color(r * scale, g * scale, b * scale);
}
Color operator/(double scale) const
{
return Color(r / scale, g / scale, b / scale);
}
Color & operator+=(const Color & other)
{
r += other.r;
g += other.g;
b += other.b;
return *this;
}
Color & operator-=(const Color & other)
{
r += other.r;
g += other.g;
b += other.b;
return *this;
}
Color & operator*=(double scale)
{
r *= scale;
g *= scale;
b *= scale;
return *this;
}
Color & operator*=(const Color & other)
{
r *= other.r;
g *= other.g;
b *= other.b;
return *this;
}
Color & operator/=(double scale)
{
r /= scale;
g /= scale;
b /= scale;
return *this;
}
Color & operator/=(const Color & other)
{
r /= other.r;
g /= other.g;
b /= other.b;
return *this;
}
Color operator+(const Color & c2)
{
return Color(r + c2.r, g + c2.g, b + c2.b);
}
Color operator-(const Color & c2)
{
return Color(r - c2.r, g - c2.g, b - c2.b);
}
static const Color black;
static const Color white;
static const Color red;
static const Color green;
static const Color blue;
static const Color yellow;
static const Color cyan;
static const Color magenta;
};
static inline Color operator*(double d, const Color & c) { return c * d; }
static inline Color operator/(double d, const Color & c) { return c / d; }
std::ostream & operator<<(std::ostream & out, const Color & color);
#endif