TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
G3D::Color4 Class Reference

#include <Color4.h>

Public Member Functions

 Color4 (const Any &any)
 
Any toAny () const
 
 Color4 ()
 
 Color4 (const Color3 &c3, float a=1.0)
 
 Color4 (const class Color4unorm8 &c)
 
 Color4 (class BinaryInput &bi)
 
 Color4 (const class Vector4 &v)
 
 Color4 (float r, float g, float b, float a=1.0)
 
 Color4 (float value[4])
 
 Color4 (const Color4 &other)
 
bool isZero () const
 
bool isOne () const
 
void serialize (class BinaryOutput &bo) const
 
void deserialize (class BinaryInput &bi)
 
Color3 rgb () const
 
float & operator[] (int i) const
 
Color4operator= (const Color4 &rkVector)
 
bool operator== (const Color4 &rkVector) const
 
bool operator!= (const Color4 &rkVector) const
 
size_t hashCode () const
 
Color4 operator+ (const Color4 &rkVector) const
 
Color4 operator- (const Color4 &rkVector) const
 
Color4 operator* (float fScalar) const
 
Color4 operator* (const Color4 &k) const
 
Color4operator*= (const Color4 &c)
 
Color4 operator/ (float fScalar) const
 
Color4 operator- () const
 
Color4operator+= (const Color4 &rkVector)
 
Color4operator-= (const Color4 &rkVector)
 
Color4operator*= (float fScalar)
 
Color4operator/= (float fScalar)
 
bool fuzzyEq (const Color4 &other) const
 
bool fuzzyNe (const Color4 &other) const
 
std::string toString () const
 
Color4 max (const Color4 &other) const
 
Color4 min (const Color4 &other) const
 
float sum () const
 
Color4 lerp (const Color4 &other, float a) const
 
bool isFinite () const
 
Color3 bgr () const
 

Static Public Member Functions

static const Color4one ()
 
static Color4 fromARGB (uint32)
 
static const Color4zero ()
 
static const Color4clear ()
 
static const Color4inf ()
 
static const Color4nan ()
 

Public Attributes

float r
 
float g
 
float b
 
float a
 

Private Member Functions

bool operator< (const Color4 &) const
 
bool operator> (const Color4 &) const
 
bool operator<= (const Color4 &) const
 
bool operator>= (const Color4 &) const
 

Friends

Color4 operator* (double fScalar, const Color4 &rkVector)
 

Detailed Description

Do not subclass– this implementation makes assumptions about the memory layout.

Constructor & Destructor Documentation

G3D::Color4::Color4 ( const Any any)
Parameters
anyMust be in one of the following forms:
25  {
26  *this = Color4::zero();
27 
28  any.verifyNameBeginsWith("Color", "Power", "Radiance", "Irradiance", "Energy", "Radiosity", "Biradiance");
29 
30  if (any.name().find('3') != std::string::npos) {
31  // This is a Color3 constructor--extend with alpha = 1
32  *this = Color4(Color3(any), 1.0f);
33  } else {
34 
35  if (any.type() == Any::TABLE) {
36  any.verifyName("Color4");
37  AnyTableReader atr(any);
38  atr.getIfPresent("r", r);
39  atr.getIfPresent("g", g);
40  atr.getIfPresent("b", b);
41  atr.getIfPresent("a", a);
42  atr.verifyDone();
43  } else if (toLower(any.name()) == "color4") {
44  r = any[0];
45  g = any[1];
46  b = any[2];
47  a = any[3];
48  } else {
49  any.verifyName("Color4::fromARGB");
50  *this = Color4::fromARGB((uint32)any[0].number());
51  }
52  }
53 }
Definition: Any.h:187
float a
Definition: Color4.h:97
bool any(float x)
Definition: g3dmath.h:424
Color4()
Definition: Color4.h:56
float b
Definition: Color4.h:97
float r
Definition: Color4.h:97
std::string toLower(const std::string &x)
Definition: stringutils.cpp:223
uint32_t uint32
Definition: Define.h:150
static Color4 fromARGB(uint32)
Definition: Color4.cpp:112
float g
Definition: Color4.h:97
static const Color4 & zero()
Definition: Color4.cpp:69

+ Here is the call graph for this function:

G3D::Color4::Color4 ( )
inline

Initializes to all zero

56 : r(0), g(0), b(0), a(0) {}
float a
Definition: Color4.h:97
float b
Definition: Color4.h:97
float r
Definition: Color4.h:97
float g
Definition: Color4.h:97

+ Here is the caller graph for this function:

G3D::Color4::Color4 ( const Color3 c3,
float  a = 1.0 
)
inline
195  {
196  r = c3.r;
197  g = c3.g;
198  b = c3.b;
199  this->a = a;
200 }
float a
Definition: Color4.h:97
float b
Definition: Color4.h:97
float r
Definition: Color4.h:97
float g
Definition: Color4.h:97
G3D::Color4::Color4 ( const class Color4unorm8 &  c)
G3D::Color4::Color4 ( class BinaryInput bi)
121  {
122  deserialize(bi);
123 }
void deserialize(class BinaryInput &bi)
Definition: Color4.cpp:126

+ Here is the call graph for this function:

G3D::Color4::Color4 ( const class Vector4 v)
G3D::Color4::Color4 ( float  r,
float  g,
float  b,
float  a = 1.0 
)
inline
208  :
209  r(r), g(g), b(b), a(a) {
210 }
float a
Definition: Color4.h:97
float b
Definition: Color4.h:97
float r
Definition: Color4.h:97
float g
Definition: Color4.h:97
G3D::Color4::Color4 ( float  value[4])
inline
213  {
214  r = afCoordinate[0];
215  g = afCoordinate[1];
216  b = afCoordinate[2];
217  a = afCoordinate[3];
218 }
float a
Definition: Color4.h:97
float b
Definition: Color4.h:97
float r
Definition: Color4.h:97
float g
Definition: Color4.h:97
G3D::Color4::Color4 ( const Color4 other)
inline

Initialize from another color.

223  {
224 
225  r = other.r;
226  g = other.g;
227  b = other.b;
228  a = other.a;
229 }
float a
Definition: Color4.h:97
float b
Definition: Color4.h:97
float r
Definition: Color4.h:97
float g
Definition: Color4.h:97

Member Function Documentation

Color3 G3D::Color4::bgr ( ) const
inline
177  {
178  return Color3(b, g, r);
179  }
float b
Definition: Color4.h:97
float r
Definition: Color4.h:97
float g
Definition: Color4.h:97
const Color4 & G3D::Color4::clear ( )
static
87  {
88  return Color4::zero();
89 }
static const Color4 & zero()
Definition: Color4.cpp:69

+ Here is the call graph for this function:

void G3D::Color4::deserialize ( class BinaryInput bi)
126  {
127  r = bi.readFloat32();
128  g = bi.readFloat32();
129  b = bi.readFloat32();
130  a = bi.readFloat32();
131 }
float a
Definition: Color4.h:97
float b
Definition: Color4.h:97
float r
Definition: Color4.h:97
float g
Definition: Color4.h:97

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Color4 G3D::Color4::fromARGB ( uint32  x)
static

Initialize from an HTML-style color (e.g. 0xFFFF0000 == RED)

112  {
113  return Color4(
114  (float)((x >> 16) & 0xFF),
115  (float)((x >> 8) & 0xFF),
116  (float)(x & 0xFF),
117  (float)((x >> 24) & 0xFF)) / 255.0;
118 }
Color4()
Definition: Color4.h:56
G3D::int16 x
Definition: Vector2int16.h:37

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool G3D::Color4::fuzzyEq ( const Color4 other) const
inline
239  {
240  Color4 dif = (*this - other);
241  return G3D::fuzzyEq(dif.r * dif.r + dif.g * dif.g + dif.b * dif.b + dif.a * dif.a, 0);
242 }
Color4()
Definition: Color4.h:56
bool fuzzyEq(double a, double b)
Definition: g3dmath.h:857

+ Here is the call graph for this function:

bool G3D::Color4::fuzzyNe ( const Color4 other) const
inline
246  {
247  Color4 dif = (*this - other);
248  return G3D::fuzzyNe(dif.r * dif.r + dif.g * dif.g + dif.b * dif.b + dif.a * dif.a, 0);
249 }
bool fuzzyNe(double a, double b)
Definition: g3dmath.h:861
Color4()
Definition: Color4.h:56

+ Here is the call graph for this function:

size_t G3D::Color4::hashCode ( ) const
103  {
104  unsigned int rhash = (*(int*)(void*)(&r));
105  unsigned int ghash = (*(int*)(void*)(&g));
106  unsigned int bhash = (*(int*)(void*)(&b));
107  unsigned int ahash = (*(int*)(void*)(&a));
108 
109  return rhash + (ghash * 37) + (bhash * 101) + (ahash * 241);
110 }
float a
Definition: Color4.h:97
float b
Definition: Color4.h:97
float r
Definition: Color4.h:97
float g
Definition: Color4.h:97

+ Here is the caller graph for this function:

const Color4 & G3D::Color4::inf ( )
static
75  {
76  static Color4 c((float)G3D::finf(), (float)G3D::finf(), (float)G3D::finf(), (float)G3D::finf());
77  return c;
78 }
float finf()
Definition: g3dmath.cpp:71
Color4()
Definition: Color4.h:56

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool G3D::Color4::isFinite ( ) const
inline
173  {
175  }
float a
Definition: Color4.h:97
float b
Definition: Color4.h:97
float r
Definition: Color4.h:97
float g
Definition: Color4.h:97
bool isFinite(double x)
Definition: g3dmath.h:525

+ Here is the call graph for this function:

bool G3D::Color4::isOne ( ) const
inline
82  {
83  return (r == 1.0f) && (g == 1.0f) && (b == 1.0f) && (a == 1.0f);
84  }
float a
Definition: Color4.h:97
float b
Definition: Color4.h:97
float r
Definition: Color4.h:97
float g
Definition: Color4.h:97
bool G3D::Color4::isZero ( ) const
inline
78  {
79  return (r == 0.0f) && (g == 0.0f) && (b == 0.0f) && (a == 0.0f);
80  }
float a
Definition: Color4.h:97
float b
Definition: Color4.h:97
float r
Definition: Color4.h:97
float g
Definition: Color4.h:97
Color4 G3D::Color4::lerp ( const Color4 other,
float  a 
) const
inline
160  {
161  return (*this) + (other - *this) * a;
162 
163  }
float a
Definition: Color4.h:97

+ Here is the caller graph for this function:

Color4 G3D::Color4::max ( const Color4 other) const
inline
147  {
148  return Color4(G3D::max(r, other.r), G3D::max(g, other.g), G3D::max(b, other.b), G3D::max(a, other.a));
149  }
float a
Definition: Color4.h:97
T max(const T &x, const T &y)
Definition: g3dmath.h:320
Color4()
Definition: Color4.h:56
float b
Definition: Color4.h:97
float r
Definition: Color4.h:97
float g
Definition: Color4.h:97

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Color4 G3D::Color4::min ( const Color4 other) const
inline
151  {
152  return Color4(G3D::min(r, other.r), G3D::min(g, other.g), G3D::min(b, other.b), G3D::min(a, other.a));
153  }
float a
Definition: Color4.h:97
Color4()
Definition: Color4.h:56
float b
Definition: Color4.h:97
T min(const T &x, const T &y)
Definition: g3dmath.h:305
float r
Definition: Color4.h:97
float g
Definition: Color4.h:97

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const Color4 & G3D::Color4::nan ( )
static
81  {
82  static Color4 c((float)G3D::fnan(), (float)G3D::fnan(), (float)G3D::fnan(), (float)G3D::fnan());
83  return c;
84 }
float fnan()
Definition: g3dmath.cpp:82
Color4()
Definition: Color4.h:56

+ Here is the call graph for this function:

const Color4 & G3D::Color4::one ( )
static
63  {
64  const static Color4 x(1.0f, 1.0f, 1.0f, 1.0f);
65  return x;
66 }
Color4()
Definition: Color4.h:56
G3D::int16 x
Definition: Vector2int16.h:37
bool G3D::Color4::operator!= ( const Color4 rkVector) const
inline
269  {
270  return ( r != other.r || g != other.g || b != other.b || a != other.a);
271 }
float a
Definition: Color4.h:97
float b
Definition: Color4.h:97
float r
Definition: Color4.h:97
float g
Definition: Color4.h:97
Color4 G3D::Color4::operator* ( float  fScalar) const
inline
285  {
286  return Color4(fScalar * r, fScalar * g, fScalar * b, fScalar * a);
287 }
float a
Definition: Color4.h:97
Color4()
Definition: Color4.h:56
float b
Definition: Color4.h:97
float r
Definition: Color4.h:97
float g
Definition: Color4.h:97

+ Here is the call graph for this function:

Color4 G3D::Color4::operator* ( const Color4 k) const
inline
120  {
121  return Color4(r*k.r, g*k.g, b*k.b, a * k.a);
122  }
float a
Definition: Color4.h:97
Color4()
Definition: Color4.h:56
float b
Definition: Color4.h:97
float r
Definition: Color4.h:97
float g
Definition: Color4.h:97

+ Here is the call graph for this function:

Color4& G3D::Color4::operator*= ( const Color4 c)
inline
124  {
125  r *= c.r;
126  g *= c.g;
127  b *= c.b;
128  a *= c.a;
129  return *this;
130  }
float a
Definition: Color4.h:97
float b
Definition: Color4.h:97
float r
Definition: Color4.h:97
float g
Definition: Color4.h:97
Color4 & G3D::Color4::operator*= ( float  fScalar)
inline
324  {
325  r *= fScalar;
326  g *= fScalar;
327  b *= fScalar;
328  a *= fScalar;
329  return *this;
330 }
float a
Definition: Color4.h:97
float b
Definition: Color4.h:97
float r
Definition: Color4.h:97
float g
Definition: Color4.h:97
Color4 G3D::Color4::operator+ ( const Color4 rkVector) const
inline
274  {
275  return Color4(r + other.r, g + other.g, b + other.b, a + other.a);
276 }
float a
Definition: Color4.h:97
Color4()
Definition: Color4.h:56
float b
Definition: Color4.h:97
float r
Definition: Color4.h:97
float g
Definition: Color4.h:97

+ Here is the call graph for this function:

Color4 & G3D::Color4::operator+= ( const Color4 rkVector)
inline
304  {
305  r += other.r;
306  g += other.g;
307  b += other.b;
308  a += other.a;
309  return *this;
310 }
float a
Definition: Color4.h:97
float b
Definition: Color4.h:97
float r
Definition: Color4.h:97
float g
Definition: Color4.h:97
Color4 G3D::Color4::operator- ( const Color4 rkVector) const
inline
279  {
280  return Color4(r - other.r, g - other.g, b - other.b, a - other.a);
281 }
float a
Definition: Color4.h:97
Color4()
Definition: Color4.h:56
float b
Definition: Color4.h:97
float r
Definition: Color4.h:97
float g
Definition: Color4.h:97

+ Here is the call graph for this function:

Color4 G3D::Color4::operator- ( ) const
inline
291  {
292  return Color4(-r, -g, -b, -a);
293 }
float a
Definition: Color4.h:97
Color4()
Definition: Color4.h:56
float b
Definition: Color4.h:97
float r
Definition: Color4.h:97
float g
Definition: Color4.h:97

+ Here is the call graph for this function:

Color4 & G3D::Color4::operator-= ( const Color4 rkVector)
inline
314  {
315  r -= other.r;
316  g -= other.g;
317  b -= other.b;
318  a -= other.a;
319  return *this;
320 }
float a
Definition: Color4.h:97
float b
Definition: Color4.h:97
float r
Definition: Color4.h:97
float g
Definition: Color4.h:97
Color4 G3D::Color4::operator/ ( float  fScalar) const
144  {
145  Color4 kQuot;
146 
147  if (fScalar != 0.0f) {
148  float fInvScalar = 1.0f / fScalar;
149  kQuot.r = fInvScalar * r;
150  kQuot.g = fInvScalar * g;
151  kQuot.b = fInvScalar * b;
152  kQuot.a = fInvScalar * a;
153  return kQuot;
154 
155  } else {
156 
157  return Color4::inf();
158  }
159 }
static const Color4 & inf()
Definition: Color4.cpp:75
float a
Definition: Color4.h:97
Color4()
Definition: Color4.h:56
float b
Definition: Color4.h:97
float r
Definition: Color4.h:97
float g
Definition: Color4.h:97

+ Here is the call graph for this function:

Color4 & G3D::Color4::operator/= ( float  fScalar)
163  {
164  if (fScalar != 0.0f) {
165  float fInvScalar = 1.0f / fScalar;
166  r *= fInvScalar;
167  g *= fInvScalar;
168  b *= fInvScalar;
169  a *= fInvScalar;
170  } else {
171  r = (float)G3D::finf();
172  g = (float)G3D::finf();
173  b = (float)G3D::finf();
174  a = (float)G3D::finf();
175  }
176 
177  return *this;
178 }
float finf()
Definition: g3dmath.cpp:71
float a
Definition: Color4.h:97
float b
Definition: Color4.h:97
float r
Definition: Color4.h:97
float g
Definition: Color4.h:97

+ Here is the call graph for this function:

bool G3D::Color4::operator< ( const Color4 ) const
private
bool G3D::Color4::operator<= ( const Color4 ) const
private
Color4 & G3D::Color4::operator= ( const Color4 rkVector)
inline
253  {
254  r = other.r;
255  g = other.g;
256  b = other.b;
257  a = other.a;
258  return *this;
259 }
float a
Definition: Color4.h:97
float b
Definition: Color4.h:97
float r
Definition: Color4.h:97
float g
Definition: Color4.h:97
bool G3D::Color4::operator== ( const Color4 rkVector) const
inline
263  {
264  return ( r == other.r && g == other.g && b == other.b && a == other.a);
265 }
float a
Definition: Color4.h:97
float b
Definition: Color4.h:97
float r
Definition: Color4.h:97
float g
Definition: Color4.h:97
bool G3D::Color4::operator> ( const Color4 ) const
private
bool G3D::Color4::operator>= ( const Color4 ) const
private
float & G3D::Color4::operator[] ( int  i) const
inline
233  {
234  return ((float*)this)[i];
235 }
Color3 G3D::Color4::rgb ( ) const
inline
99  {
100  return Color3(r, g, b);
101  }
float b
Definition: Color4.h:97
float r
Definition: Color4.h:97
float g
Definition: Color4.h:97

+ Here is the caller graph for this function:

void G3D::Color4::serialize ( class BinaryOutput bo) const
134  {
135  bo.writeFloat32(r);
136  bo.writeFloat32(g);
137  bo.writeFloat32(b);
138  bo.writeFloat32(a);
139 }
float a
Definition: Color4.h:97
float b
Definition: Color4.h:97
float r
Definition: Color4.h:97
float g
Definition: Color4.h:97

+ Here is the call graph for this function:

float G3D::Color4::sum ( ) const
inline

r + g + b + a

156  {
157  return r + g + b + a;
158  }
float a
Definition: Color4.h:97
float b
Definition: Color4.h:97
float r
Definition: Color4.h:97
float g
Definition: Color4.h:97
Any G3D::Color4::toAny ( ) const

Converts the Color4 to an Any.

56  {
57  Any any(Any::ARRAY, "Color4");
58  any.append(r, g, b, a);
59  return any;
60 }
float a
Definition: Color4.h:97
bool any(float x)
Definition: g3dmath.h:424
Definition: Any.h:187
float b
Definition: Color4.h:97
float r
Definition: Color4.h:97
float g
Definition: Color4.h:97

+ Here is the call graph for this function:

std::string G3D::Color4::toString ( ) const
182  {
183  return G3D::format("(%g, %g, %g, %g)", r, g, b, a);
184 }
float a
Definition: Color4.h:97
float b
Definition: Color4.h:97
float r
Definition: Color4.h:97
std::string __cdecl format(const char *fmt...) G3D_CHECK_PRINTF_ARGS
float g
Definition: Color4.h:97

+ Here is the call graph for this function:

const Color4 & G3D::Color4::zero ( )
static
69  {
70  static Color4 c(0.0f, 0.0f, 0.0f, 0.0f);
71  return c;
72 }
Color4()
Definition: Color4.h:56

+ Here is the caller graph for this function:

Friends And Related Function Documentation

Color4 operator* ( double  fScalar,
const Color4 rkVector 
)
friend

Member Data Documentation

float G3D::Color4::a
float G3D::Color4::b
float G3D::Color4::g
float G3D::Color4::r

Channel values.


The documentation for this class was generated from the following files: