TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Color1.h
Go to the documentation of this file.
1 
14 #ifndef G3D_Color1_h
15 #define G3D_Color1_h
16 
17 #include "G3D/platform.h"
18 #include "G3D/g3dmath.h"
19 #include "G3D/unorm8.h"
20 #include "G3D/HashTrait.h"
21 #include <string>
22 
23 namespace G3D {
24 
28 class Color1 {
29 private:
30  // Hidden operators
31  bool operator<(const Color1&) const;
32  bool operator>(const Color1&) const;
33  bool operator<=(const Color1&) const;
34  bool operator>=(const Color1&) const;
35 
36 public:
37  float value;
38 
42  inline Color1() : value(0) {}
43 
44  Color1(class BinaryInput& bi);
45 
46  inline explicit Color1(float v) : value(v) {
47  }
48 
49  inline explicit Color1(unorm8 v) : value(v) {
50  }
51 
52  inline bool isZero() const {
53  return value == 0.0f;
54  }
55 
56  inline bool isOne() const {
57  return value == 1.0f;
58  }
59 
60  static const Color1& one();
61 
62  static const Color1& zero();
63 
65  class Color3 rgb() const;
66 
67  explicit Color1(const class Color1unorm8& other);
68 
69  void serialize(class BinaryOutput& bo) const;
70  void deserialize(class BinaryInput& bi);
71 
72  Color1 operator+ (const Color1& other) const {
73  return Color1(value + other.value);
74  }
75 
77  Color1 operator+ (const float other) const {
78  return Color1(value + other);
79  }
80 
81  Color1& operator+= (const Color1 other) {
82  value += other.value;
83  return *this;
84  }
85 
86  Color1& operator-= (const Color1 other) {
87  value -= other.value;
88  return *this;
89  }
90 
91  Color1 operator- (const Color1& other) const {
92  return Color1(value - other.value);
93  }
94 
96  Color1 operator- (const float other) const {
97  return Color1(value - other);
98  }
99 
100  Color1 operator- () const {
101  return Color1(-value);
102  }
103 
104  Color1 operator* (const Color1& other) const {
105  return Color1(value * other.value);
106  }
107 
108  Color1& operator*=(const Color1 other) {
109  value *= other.value;
110  return *this;
111  }
112 
113  Color1& operator*=(const float other) {
114  value *= other;
115  return *this;
116  }
117 
118  Color1& operator/=(const float other) {
119  value /= other;
120  return *this;
121  }
122 
123  Color1& operator/=(const Color1 other) {
124  value /= other.value;
125  return *this;
126  }
127 
128  Color1 operator* (const float other) const {
129  return Color1(value * other);
130  }
131 
132  Color1 operator/ (const Color1& other) const {
133  return Color1(value / other.value);
134  }
135 
136  Color1 operator/ (const float other) const {
137  return Color1(value / other);
138  }
139 
140  inline Color1 max(const Color1& other) const {
141  return Color1(G3D::max(value, other.value));
142  }
143 
144  inline Color1 min(const Color1& other) const {
145  return Color1(G3D::min(value, other.value));
146  }
147 
148  inline Color1 lerp(const Color1& other, float a) const {
149  return Color1(value + (other.value - value) * a);
150 
151  }
152 
153  inline size_t hashCode() const {
154  return (size_t)(value * 0xFFFFFF);
155  }
156 };
157 
158 }
159 
160 template <>
161 struct HashTrait<G3D::Color1> {
162  static size_t hashCode(const G3D::Color1& key) {
163  return key.hashCode();
164  }
165 };
166 
167 inline G3D::Color1 operator*(float f, G3D::Color1 c) {
168  return c * f;
169 }
170 
171 #endif
unorm8
Definition: unorm8.h:33
static size_t hashCode(const G3D::Color1 &key)
Definition: Color1.h:162
Color1 min(const Color1 &other) const
Definition: Color1.h:144
bool operator>(const Color1 &) const
bool operator>=(const Color1 &) const
Color1()
Definition: Color1.h:42
static const Color1 & zero()
Definition: Color1.cpp:27
Color1 & operator*=(const Color1 other)
Definition: Color1.h:108
Color1 operator*(const Color1 &other) const
Definition: Color1.h:104
Color1 & operator+=(const Color1 other)
Definition: Color1.h:81
Definition: BinaryInput.h:69
Color1 & operator/=(const float other)
Definition: Color1.h:118
static const Color1 & one()
Definition: Color1.cpp:21
void serialize(class BinaryOutput &bo) const
Definition: Color1.cpp:48
Color1 & operator/=(const Color1 other)
Definition: Color1.h:123
Definition: HashTrait.h:105
Definition: AABox.h:25
Color1 & operator-=(const Color1 other)
Definition: Color1.h:86
bool isZero() const
Definition: Color1.h:52
T max(const T &x, const T &y)
Definition: g3dmath.h:320
Color1 operator-() const
Definition: Color1.h:100
T min(const T &x, const T &y)
Definition: g3dmath.h:305
class Color3 rgb() const
Definition: Color1.cpp:38
Color1(float v)
Definition: Color1.h:46
Color1 max(const Color1 &other) const
Definition: Color1.h:140
G3D::Color1 operator*(float f, G3D::Color1 c)
Definition: Color1.h:167
bool operator<=(const Color1 &) const
size_t hashCode() const
Definition: Color1.h:153
Definition: Color1.h:28
Color1 lerp(const Color1 &other, float a) const
Definition: Color1.h:148
Definition: Color3.h:33
Color1 operator+(const Color1 &other) const
Definition: Color1.h:72
Color1(unorm8 v)
Definition: Color1.h:49
Definition: BinaryOutput.h:52
void deserialize(class BinaryInput &bi)
Definition: Color1.cpp:43
Color1 & operator*=(const float other)
Definition: Color1.h:113
bool isOne() const
Definition: Color1.h:56
bool operator<(const Color1 &) const
#define const
Definition: zconf.h:217
Color1 operator/(const Color1 &other) const
Definition: Color1.h:132
float value
Definition: Color1.h:37