-
Notifications
You must be signed in to change notification settings - Fork 0
/
fcolor.h
67 lines (56 loc) · 1.26 KB
/
fcolor.h
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
#pragma once
#include <cstdio>
#include <algorithm>
class FColor {
public:
float red, green, blue;
FColor():
red(0), green(0), blue(0)
{}
FColor(float _r, float _g, float _b):
red(_r), green(_g), blue(_b)
{}
FColor(const FColor& c):
red(c.red), green(c.green), blue(c.blue)
{}
void print() const {
std::printf("[%f, %f, %f]\n", red, green, blue);
}
FColor operator+(const FColor& _c) const {
FColor c(
red + _c.red,
green + _c.green,
blue + _c.blue
);
return c;
}
void operator+=(const FColor& _c) {
*this = *this + _c;
}
FColor operator*(const FColor& _c) const {
FColor c(
red * _c.red,
green * _c.green,
blue * _c.blue
);
return c;
}
template <class T>
FColor mult(const T n) const {
FColor c(
red * n,
green * n,
blue * n
);
return c;
}
FColor normalize() const {
using namespace std;
FColor c(
min(max(red, 0.0f), 1.0f),
min(max(green, 0.0f), 1.0f),
min(max(blue, 0.0f), 1.0f)
);
return c;
}
};