-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcolor.cpp
65 lines (55 loc) · 871 Bytes
/
color.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "color.h"
#include <math.h>
Color::Color() :
r(1.0),
g(1.0),
b(1.0),
a(1.0) {
}
Color::Color(int r, int g, int b, float a) :
r((float)r / 255.0),
g((float)g / 255.0),
b((float)b / 255.0),
a(a) {
}
Color::Color(const Color &other) :
r(other.r),
g(other.g),
b(other.b),
a(other.a) {
}
Color& Color::operator=(const Color &other) {
r = other.r;
g = other.g;
b = other.b;
a = other.a;
return *this;
}
void Color::toArray(float *dst) {
dst[0] = r;
dst[1] = g;
dst[2] = b;
dst[3] = a;
}
float& Color::operator[](int index) {
switch(index){
case 0:
return r;
case 1:
return g;
case 2:
return b;
}
return a;
}
const float& Color::operator[](int index) const {
switch(index){
case 0:
return r;
case 1:
return g;
case 2:
return b;
}
return a;
}