00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef _GFX_COLOR3_
00026 #define _GFX_COLOR3_
00027
00028 #include <gfx/gfx>
00029
00030 #include <iostream>
00031
00032 namespace gfx {
00033
00034 class Color3 {
00035
00036 public:
00037 Color3() { r=g=b=Real(0); }
00038 Color3(const String& name) { *this = lookupColor(name); }
00039 Color3(const Color3& c) { r=c.r; g=c.g; b=c.b; }
00040 Color3(Real rc, Real gc, Real bc)
00041 { r = rc; g = gc; b = bc; }
00042 ~Color3() {}
00043
00044 Color3& operator=(const Color3& c)
00045 { r=c.r; g=c.g; b=c.b; return *this; }
00046
00047 bool operator==(const Color3& c) const
00048 { return ((r==c.r) && (g==c.g) && (b==c.b)); }
00049
00050 bool equals(const Color3& c, Real epsilon = consts::epsilon) const
00051 { return base::equals(r,c.r,epsilon) && base::equals(g,c.g,epsilon) && base::equals(b,c.b,epsilon); }
00052
00053 void setZero() { r=g=b=Real(0); }
00054
00055 Color3& operator*=(Real s)
00056 { s=base::abs(s); if (s<1.0) { r*=s; g*=s; b*=s; } return *this; }
00057
00058 static Color3 interpolate(const Color3& c1, const Color3& c2, Real t)
00059 { return Color3((1.0-t)*c1.r+t*c2.r,(1.0-t)*c1.g+t*c2.g,(1.0-t)*c1.b+t*c2.b); }
00060
00061 Real* c_array() { return &r; }
00062
00063 Real r,g,b;
00064
00065 protected:
00066 struct ColorDatabaseEntry {
00067 base::Byte r,g,b;
00068 String name;
00069 };
00070
00071 static ColorDatabaseEntry colorDatabase[];
00072 static Color3 lookupColor(const String& name);
00073
00074 };
00075
00076 inline Color3 operator*(const Color3& c, Real s)
00077 { Color3 r(c); r*=s; return r; }
00078
00079 inline std::ostream& operator<<(std::ostream& out, const Color3& c)
00080 { return out << "(" << c.r << "," << c.g << "," << c.b << ")"; }
00081
00082 }
00083
00084 #endif