Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: merged the proxy bache back with no conflicts

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