Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/util/color.h @ 8448

Last change on this file since 8448 was 8448, checked in by bensch, 18 years ago

merged gui back to the trunk
merged with command
merge -r8377:HEAD https://svn.orxonox.net/orxonox/branches/gui .

File size: 2.8 KB
Line 
1/*!
2 * @file color.h
3 * @brief Definition of color-calculations
4 *
5 * code borrowed from:
6 * http://www.easyrgb.com/math.php
7*/
8
9#ifndef _COLOR_H
10#define _COLOR_H
11
12#include "vector.h"
13
14//! a very abstract Class that helps transforming Colors into different Systems
15class Color
16{
17public:
18  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; };
19  Color(const Color& c) { _rgba[0] = c.r(); _rgba[1] = c.g(); _rgba[2] = c.b(); _rgba[3] = c.a(); }
20
21  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; };
22  inline bool operator==(const Color& c) const { return (r() == c.r() && g() == c.g() && b() == c.b() && a() == c.a()); };
23
24  inline float& operator[](unsigned int i) { return _rgba[i]; }
25  inline const float& operator[](unsigned int i) const { return _rgba[i]; }
26
27  inline float r() const { return _rgba[0]; }
28  inline float& r() { return _rgba[0]; }
29  inline float g() const { return _rgba[1]; }
30  inline float& g() { return _rgba[1]; }
31  inline float b() const { return _rgba[2]; }
32  inline float& b() { return _rgba[2]; }
33  inline float a() const { return _rgba[3]; }
34  inline float& a() { return _rgba[3]; }
35
36
37
38
39  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; };
40  void setColor(const Color& c) { r() = c.r();  g()= c.g(); b() = c.b(); a() = c.a(); };
41
42  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()))); }
43  /// Maths
44  inline const Color& operator+=(const Color& c) { r()+=c.r(); g()+=c.g(); b()+=c.b(); a()+=c.a(); return *this; };
45  inline Color operator+(const Color& c) const { return Color(r()+c.r(), g()+c.g(), b()+c.b(), a()+c.a()); };
46  inline const Color& operator-=(const Color& c) { r()-=c.r(); g()-=c.g(); b()-=c.b(); a()-=c.a(); return *this; };
47  inline Color operator-(const Color& c) const { return Color(r()-c.r(), g()-c.g(), b()-c.b(), a()-c.a()); };
48  inline Color operator*(float v) const { return Color(r()*v, g()*v, b()*v, a()*v); };
49
50  void slerp(const Color& c, float v) { *this += (c - *this) * v; };
51
52  void debug() const;
53
54  /// STATIC TRANSFORMATIONS
55public:
56  static Vector RGBtoHSV (const Vector& RGB);
57  static void RGBtoHSV (const Vector& RGB, Vector& HSV);
58  static Vector HSVtoRGB (const Vector& HSV);
59  static void HSVtoRGB (const Vector& HSV, Vector& RGB);
60
61private:
62  static float minrgb(float r, float g, float b);
63  static float maxrgb(float r, float g, float b);
64
65private:
66  float       _rgba[4]; //!< Color Values
67
68  /*  float       _r;     //!< Red Value.
69  float       _g;     //!< Green Value.
70  float       _b;     //!< Blue Value.
71  float       _a;     //!< Alpha Value.*/
72};
73
74#endif /* _COLOR_H */
Note: See TracBrowser for help on using the repository browser.