Changeset 9869 in orxonox.OLD for trunk/src/lib/util/color.h
- Timestamp:
- Oct 3, 2006, 12:19:30 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/util/color.h
r9656 r9869 14 14 #include "vector.h" 15 15 16 //! a very abstract Class that helps transforming Colors into different Systems 16 //! A Class that handles Colors. 17 /** 18 * A Color is a collection of 4 values: 19 * <ul> 20 * <li>Red</li> 21 * <li>Green</li> 22 * <li>Blue</li> 23 * <li>Alpha</li> 24 * </ul> 25 * With these four values any color of the entire spectrum can be defined. 26 * 27 * By default a Color lies between 0 and 1 for each component. 28 * for example [1,0,0,.5] means red and half visible. 29 */ 17 30 class Color 18 31 { 19 32 public: 33 /** @param r red, @param g green @param b blue @param a alpha @brief constructs a Color. */ 20 34 Color(float r = 0.0f, float g = 0.0f, float b = 0.0f, float a = 1.0f) { _rgba[0] = r; _rgba[1] = g; _rgba[2] = b; _rgba[3] = a; }; 35 /** @param c Color @brief copy constructor */ 21 36 Color(const Color& c) { _rgba[0] = c.r(); _rgba[1] = c.g(); _rgba[2] = c.b(); _rgba[3] = c.a(); } 22 37 38 /** @param c the Color to set to this color @returns the copied color */ 23 39 inline const Color& operator=(const Color& c) { _rgba[0] = c.r(); _rgba[1] = c.g(); _rgba[2] = c.b(); _rgba[3] = c.a(); return *this; }; 40 /** @param c the color to compare @returns true on match. @brief compares two colors */ 24 41 inline bool operator==(const Color& c) const { return (r() == c.r() && g() == c.g() && b() == c.b() && a() == c.a()); }; 25 42 43 /** @returns the i'th Value of the Color @param i part of the color 0:r, 1:g, 2:b, 3:a */ 26 44 inline float& operator[](unsigned int i) { return _rgba[i]; } 45 /** @returns a Constant Value of the color. @param i part of the color 0:r, 1:g, 2:b, 3:a */ 27 46 inline const float& operator[](unsigned int i) const { return _rgba[i]; } 28 47 48 /** @returns the red part. */ 29 49 inline float r() const { return _rgba[0]; } 50 /** @returns the reference to the red part */ 30 51 inline float& r() { return _rgba[0]; } 52 /** @returns the green part. */ 31 53 inline float g() const { return _rgba[1]; } 54 /** @returns the reference to the green part */ 32 55 inline float& g() { return _rgba[1]; } 56 /** @returns the blue part */ 33 57 inline float b() const { return _rgba[2]; } 58 /** @returns the reference to the blue part */ 34 59 inline float& b() { return _rgba[2]; } 60 /** @returns the alpha part */ 35 61 inline float a() const { return _rgba[3]; } 62 /** @returns the reference to the alpha part */ 36 63 inline float& a() { return _rgba[3]; } 37 64 38 65 39 40 66 /** @param r red, @param g green @param b blue @param a alpha @brief sets the color. */ 41 67 void setColor(float r = 0.0f, float g = 0.0f, float b = 0.0f, float a = 1.0f) { _rgba[0] = r; _rgba[1] = g; _rgba[2] = b; _rgba[3] = a; }; 68 /** @param c the color to set. @brief sets the color. */ 42 69 void setColor(const Color& c) { r() = c.r(); g()= c.g(); b() = c.b(); a() = c.a(); }; 43 70 71 /** @returns the distance to the color @param c the color to calculate the distance to. */ 44 72 inline float dist(const Color& c) const { return (sqrt((r()-c.r())*(r()-c.r()) + (g()-c.g())*(g()-c.g()) + (b()-c.b())*(b()-c.b()) + (a()-c.a())*(a()-c.a()))); } 45 73 /// Maths 74 /** @param c the color to add to this one @returns the two added colors */ 46 75 inline const Color& operator+=(const Color& c) { r()+=c.r(); g()+=c.g(); b()+=c.b(); a()+=c.a(); return *this; }; 76 /** @returns the result of the added colors @param c the color to add */ 47 77 inline Color operator+(const Color& c) const { return Color(r()+c.r(), g()+c.g(), b()+c.b(), a()+c.a()); }; 78 /** @param c the color to substract to this one @returns the two substracted colors */ 48 79 inline const Color& operator-=(const Color& c) { r()-=c.r(); g()-=c.g(); b()-=c.b(); a()-=c.a(); return *this; }; 80 /** @returns the result of the substracted colors @param c the color to substract */ 49 81 inline Color operator-(const Color& c) const { return Color(r()-c.r(), g()-c.g(), b()-c.b(), a()-c.a()); }; 82 /** @param v the multiplier @returns the Color multiplied by v */ 50 83 inline const Color& operator*=(float v) { r()*=v, g()*=v, b()*=v, a()*=v; return *this; }; 84 /** @param v the multiplier @returns a multiplied color */ 51 85 inline Color operator*(float v) const { return Color(r()*v, g()*v, b()*v, a()*v); }; 52 86 87 /** @param c the color to slerp to @param v how much to slerp [0:1] @brief moves the color into the direction of another color */ 53 88 void slerp(const Color& c, float v) { *this += (c - *this) * v; }; 54 89 void slerpHSV(const Color& c, float v); 55 56 90 static Color slerpHSVColor(const Color& from, const Color& to, float v); 57 91 … … 75 109 static const Color white; 76 110 static const Color black; 77 static const Color orx;78 111 79 112 private: 80 float _rgba[4]; //!< Color Values 81 82 /* float _r; //!< Red Value. 83 float _g; //!< Green Value. 84 float _b; //!< Blue Value. 85 float _a; //!< Alpha Value.*/ 113 float _rgba[4]; //!< Color Values [r,g,b,a] (red green blue alpha) 86 114 }; 87 115
Note: See TracChangeset
for help on using the changeset viewer.