t
Loading...
Searching...
No Matches
Color.hpp
1#include "math/Vector3.hpp"
2#include <algorithm>
3
4#ifndef COLOR_HPP
5#define COLOR_HPP
6
7namespace t {
8
18class Color : public Vector3 {
19public:
20 using Vector3::Vector3;
21
39 Color(double r, double g, double b) : Vector3(r, g, b) {}
40
59 Color(int r, int g, int b, int colorDepth = 8)
60 : Vector3(r / std::pow(2, colorDepth), g / std::pow(2, colorDepth),
61 b / std::pow(2, colorDepth)) {}
62
70 explicit Color(Vector3 vector3) : Vector3(vector3.x, vector3.y, vector3.z) {}
71
78 Vector3::clamp(0, 1);
79 return *this;
80 }
81
90 double luminance() const { return x * 0.2126 + y * 0.7152 + z * 0.0722; }
91};
92
93} // namespace t
94
95#endif // COLOR_HPP
The color class.
Definition Color.hpp:18
Color(Vector3 vector3)
Creates a new color with the specified Vector3 components as normalized RGB values.
Definition Color.hpp:70
Color & clamp()
Clamps the components of this color to the range .
Definition Color.hpp:77
Color(int r, int g, int b, int colorDepth=8)
Creates a new color with the specified red, green, and blue components and the specified color depth.
Definition Color.hpp:59
double luminance() const
Returns the luminance of this color.
Definition Color.hpp:90
Color(double r, double g, double b)
Creates a new color with the specified normalized red, green, and blue components.
Definition Color.hpp:39
The 3D vector class.
Definition Vector3.hpp:20
double z
The z component of this 3D vector.
Definition Vector3.hpp:24
Vector3 & clamp(const Vector3 &min, const Vector3 &max)
Clamps the components of this 3D vector to the specified minimum and maximum 3D vectors component-wis...
Definition Vector3.hpp:199
double y
The y component of this 3D vector.
Definition Vector3.hpp:23
double x
The x component of this 3D vector.
Definition Vector3.hpp:22
Vector3(double _x, double _y, double _z)
Creates a new 3D vector with the specified components.
Definition Vector3.hpp:96
The t software 3D graphics library namespace.
Definition algorithms.hpp:12