00001 #ifndef _RGBA_H_
00002 #define _RGBA_H_
00003
00004 #include "cglib/definitions.h"
00005
00007 struct Rgba
00008 {
00009 public:
00010 float r;
00011 float g;
00012 float b;
00013 float a;
00014
00016 inline Rgba()
00017 {
00018 r = g = b = a = 0.0f;
00019 }
00020
00022 inline Rgba(float c)
00023 {
00024 r = g = b = a = c;
00025 }
00026
00028 inline Rgba(float _r, float _g, float _b)
00029 {
00030 r = _r;
00031 g = _g;
00032 b = _b;
00033 a = 1.0f;
00034 }
00035
00037 inline Rgba(float _r, float _g, float _b, float _a)
00038 {
00039 r = _r;
00040 g = _g;
00041 b = _b;
00042 a = _a;
00043 }
00044
00046 inline Rgba operator+(const Rgba &other) const {
00047 return Rgba(r + other.r, g + other.g, b + other.b, a + other.a);
00048 }
00049
00051 inline Rgba operator-(const Rgba &other) const {
00052 return Rgba(r - other.r, g - other.g, b - other.b, a - other.a);
00053 }
00054
00056 inline Rgba operator+(float c) const {
00057 return Rgba(r + c, g + c, b + c, a + c);
00058 }
00059
00061 inline Rgba &operator+=(const Rgba &other)
00062 {
00063 r += other.r;
00064 g += other.g;
00065 b += other.b;
00066 a += other.a;
00067 return *this;
00068 }
00069
00071 inline Rgba operator*(const Rgba &other) const {
00072 return Rgba(r * other.r, g * other.g, b * other.b, a * other.a);
00073 }
00074
00076 inline Rgba operator*(float c) const {
00077 return Rgba(r * c, g * c, b * c, a * c);
00078 }
00079
00081 inline Rgba &operator*=(const Rgba &other)
00082 {
00083 r *= other.r;
00084 g *= other.g;
00085 b *= other.b;
00086 a *= other.a;
00087 return *this;
00088 }
00089
00091 inline Rgba operator/(const Rgba &other) const {
00092 return Rgba(r / other.r, g / other.g, b / other.b, a / other.a);
00093 }
00094
00096 inline Rgba operator/(float c) const {
00097 float cinv = 1.0f / c;
00098 return Rgba(r * cinv, g * cinv, b * cinv, a * cinv);
00099 }
00100
00102
00109 inline void fill_array_4(float *_a)
00110 {
00111 _a[0] = r;
00112 _a[1] = g;
00113 _a[2] = b;
00114 _a[3] = a;
00115 }
00116
00118
00121 bool is_near(const Rgba &other, float threshold=EPSILON)
00122 {
00123 float absr = fabs(r - other.r);
00124 float absg = fabs(g - other.g);
00125 float absb = fabs(b - other.b);
00126 float absa = fabs(a - other.a);
00127 return (absr < EPSILON && absg < EPSILON && absb < EPSILON && absa < EPSILON);
00128 }
00129 };
00130
00132 inline Rgba operator+(float c, const Rgba &rgba)
00133 {
00134 return Rgba(rgba.r + c, rgba.g + c, rgba.b + c, rgba.a + c);
00135 }
00136
00138 inline Rgba operator*(float c, const Rgba &rgba)
00139 {
00140 return Rgba(rgba.r * c, rgba.g * c, rgba.b * c, rgba.a * c);
00141 }
00142
00143 #endif