-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathColor.cpp
77 lines (68 loc) · 1.89 KB
/
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
66
67
68
69
70
71
72
73
74
75
76
77
// Onut
#include <onut/Color.h>
#include <onut/Vector3.h>
#include <onut/Vector4.h>
const Color Color::Black(0.0f, 0.0f, 0.0f, 1.0f);
const Color Color::White(1.0f, 1.0f, 1.0f, 1.0f);
const Color Color::Transparent(0.0f, 0.0f, 0.0f, 0.0f);
const Color Color::TransparentWhite(1.0f, 1.0f, 1.0f, 0.0f);
Color::Color(const Vector3& rgb, float _a) : r(rgb.x), g(rgb.y), b(rgb.z), a(_a) {}
Color::Color(const Vector3& clr) : r(clr.x), g(clr.y), b(clr.z), a(1.f) {}
Color::Color(const Vector4& clr) : r(clr.x), g(clr.y), b(clr.z), a(clr.w) {}
Vector3 Color::ToVector3() const { return Vector3(r, g, b); }
Vector4 Color::ToVector4() const { return Vector4(r, g, b, a); }
// Binary operators
Color operator+ (const Color& C1, const Color& C2)
{
Color result;
result.r = C1.r + C2.r;
result.g = C1.g + C2.g;
result.b = C1.b + C2.b;
result.a = C1.a + C2.a;
return std::move(result);
}
Color operator- (const Color& C1, const Color& C2)
{
Color result;
result.r = C1.r - C2.r;
result.g = C1.g - C2.g;
result.b = C1.b - C2.b;
result.a = C1.a - C2.a;
return std::move(result);
}
Color operator* (const Color& C1, const Color& C2)
{
Color result;
result.r = C1.r * C2.r;
result.g = C1.g * C2.g;
result.b = C1.b * C2.b;
result.a = C1.a * C2.a;
return std::move(result);
}
Color operator* (const Color& C, float S)
{
Color result;
result.r = C.r * S;
result.g = C.g * S;
result.b = C.b * S;
result.a = C.a * S;
return std::move(result);
}
Color operator/ (const Color& C1, const Color& C2)
{
Color result;
result.r = C1.r / C2.r;
result.g = C1.g / C2.g;
result.b = C1.b / C2.b;
result.a = C1.a / C2.a;
return std::move(result);
}
Color operator* (float S, const Color& C)
{
Color result;
result.r = C.r * S;
result.g = C.g * S;
result.b = C.b * S;
result.a = C.a * S;
return std::move(result);
}