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_COLOR4_
00026 #define _GFX_COLOR4_
00027
00028 #include <gfx/gfx>
00029
00030 #include <gfx/Color3>
00031
00032 namespace gfx {
00033
00034 class Color4
00035 {
00036
00037 public:
00038 Color4() { r=g=b=a=Real(0); }
00039 Color4(const Color4& c) { r=c.r; g=c.g; b=c.b; a=c.a; }
00040 Color4(const String& name, Real ac = Real(1)) { *this = Color3(name); a=ac; }
00041 Color4(const Color3& c) { r=c.r; g=c.g; b=c.b; a=Real(1); }
00042 Color4(Real rc, Real gc, Real bc, Real ac = Real(1))
00043 { r = rc; g = gc; b = bc; a = ac; }
00044 ~Color4() {}
00045
00046 Color4& operator=(const Color4& c)
00047 { r=c.r; g=c.g; b=c.b; a=c.a; return *this; }
00048
00049 Color4& operator=(const Color3& c)
00050 { r=c.r; g=c.g; b=c.b; a=Real(1); return *this; }
00051
00052 bool operator==(const Color4& c) const
00053 { return ((r==c.r) && (g==c.g) && (b==c.b) && (a==c.a)); }
00054
00055 bool equals(const Color4& c, Real epsilon = consts::epsilon) const
00056 { return base::equals(r,c.r,epsilon) && base::equals(g,c.g,epsilon)
00057 && base::equals(b,c.b,epsilon) && base::equals(a,c.a,epsilon); }
00058
00059 void setZero() { r=g=b=a=Real(0); }
00060
00061 Color4& operator*=(Real s)
00062 { s=base::abs(s); if (s<1.0) { r*=s; g*=s; b*=s; } return *this; }
00063
00064 static Color4 interpolate(const Color4& c1, const Color4& c2, Real t)
00065 { return Color4((1.0-t)*c1.r+t*c2.r,(1.0-t)*c1.g+t*c2.g,(1.0-t)*c1.b+t*c2.b,(1.0-t)*c1.a+t*c2.a); }
00066
00067 Real* c_array() { return &r; }
00068
00069
00070 Real r,g,b,a;
00071
00072 };
00073
00074 inline std::ostream& operator<<(std::ostream& out, const Color4& c)
00075 { return out << "(" << c.r << "," << c.g << "," << c.b << "," << c.a << ")"; }
00076
00077 }
00078
00079 #endif