00001
00002
00003
00004
00005
00006 #ifndef COLOR3_H
00007 #define COLOR3_H
00008
00009 #include<iostream.h>
00010 #include<base.h>
00011
00012 #include<string>
00013
00014 class Color4;
00015 class ObjectFile;
00016
00019 class Color3
00020 {
00021 friend ostream &operator<<(ostream &stream, const Color3 &c);
00022 friend ObjectFile &operator>>(ObjectFile &f, Color3 &c);
00023 public:
00024 static void declare(const string &name, const Color3 &c);
00025 static bool find(const string &name, Color3 &c);
00026
00027
00028 Color3() {};
00029 Color3(const string &name) {
00030 find(name, *this);
00031 }
00032 Color3(float rr, float gg, float bb) : r(rr), g(gg), b(bb) {}
00033 Color3(const Color3 &c) : r(c.r), g(c.g), b(c.b) {}
00034
00035
00036 float &operator [](unsigned int i) {
00037 return ((float*)(this))[i];
00038 }
00039
00040 Color3 &clamp() {
00041 r = ::clamp(r);
00042 g = ::clamp(g);
00043 b = ::clamp(b);
00044 return *this;
00045 }
00046 Color3 &lerp(Color3 &from, Color3 &to, float t);
00047
00048
00049 Color3 &operator =(const Color3 &c) {
00050 r = c.r;
00051 g = c.g;
00052 b = c.b;
00053 return *this;
00054 }
00055 Color3 &operator =(const Color4 &c);
00056 void operator -=(const Color3 &c) {
00057 r -= c.r;
00058 g -= c.g;
00059 b -= c.b;
00060 }
00061 void operator += (const Color3 &c) {
00062 r += c.r;
00063 g += c.g;
00064 b += c.b;
00065 }
00066 void operator *=(float s) {
00067 r *= s;
00068 g *= s;
00069 b *= s;
00070 }
00071 void operator *=(const Color3 &c) {
00072 r *= c.r;
00073 g *= c.g;
00074 b *= c.b;
00075 }
00076 void operator /=(float s) {
00077 r /= s;
00078 g /= s;
00079 b /= s;
00080 }
00081
00082
00083 Color3 operator -(const Color3 &c) const {
00084 Color3 cc(r - c.r, g - c.g, b - c.b);
00085 return cc;
00086 }
00087 Color3 operator +(const Color3 &c) const {
00088 Color3 cc(r + c.r, g + c.g, b + c.b);
00089 return cc;
00090 }
00091 Color3 operator *(float s) const {
00092 Color3 v(r * s, g * s, b * s);
00093 return v;
00094 }
00095 Color3 operator *(const Color3 &c) const {
00096 Color3 cc(r * c.r, g * c.g, b * c.b);
00097 return cc;
00098 }
00099 Color3 operator /(float s) const {
00100 Color3 v(r / s, g / s, b / s);
00101 return v;
00102 }
00103 void operator <<(Color3 &c);
00104
00105 float gray() const;
00106
00107 float r, g, b;
00108 };
00109 #endif