ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
RGBColor.cpp
Go to the documentation of this file.
1#include "RGBColor.h"
2
4
5RGBColor::RGBColor(const uint8_t& R, const uint8_t& G, const uint8_t& B) {
6 this->R = R;
7 this->G = G;
8 this->B = B;
9}
10
12 this->R = rgbColor.R;
13 this->G = rgbColor.G;
14 this->B = rgbColor.B;
15}
16
18 this->R = color.X;
19 this->G = color.Y;
20 this->B = color.Z;
21}
22
23void RGBColor::SetColor(const uint8_t& R, const uint8_t& G, const uint8_t& B) {
24 this->R = R;
25 this->G = G;
26 this->B = B;
27}
28
29RGBColor RGBColor::Scale(const uint8_t& maxBrightness) {
30 uint8_t sR, sG, sB;
31
32 sR = (uint8_t)R * (uint8_t)maxBrightness / 255;
33 sG = (uint8_t)G * (uint8_t)maxBrightness / 255;
34 sB = (uint8_t)B * (uint8_t)maxBrightness / 255;
35
36 sR = sR > 255 ? 255 : sR;
37 sG = sG > 255 ? 255 : sG;
38 sB = sB > 255 ? 255 : sB;
39
40 sR = sR < 0 ? 0 : sR;
41 sG = sG < 0 ? 0 : sG;
42 sB = sB < 0 ? 0 : sB;
43
44 return RGBColor(sR, sG, sB);
45}
46
48 int sR, sG, sB;
49
50 sR = (uint8_t)R + (uint8_t)value;
51 sG = (uint8_t)G + (uint8_t)value;
52 sB = (uint8_t)B + (uint8_t)value;
53
54 sR = sR > 255 ? 255 : sR;
55 sG = sG > 255 ? 255 : sG;
56 sB = sB > 255 ? 255 : sB;
57
58 sR = sR < 0 ? 0 : sR;
59 sG = sG < 0 ? 0 : sG;
60 sB = sB < 0 ? 0 : sB;
61
62 return RGBColor(sR, sG, sB);
63}
64
66 //hueDeg = (int)hueDeg % 360;
67 //shift color space by rotating rgb vector about diagonal vector (1, 1, 1)
68 float hueRad = hueDeg * Mathematics::MPI / 180.0f;
69 float hueRat = 0.5f * sinf(hueRad / 2.0f);//2.0f for quaternion creation
72
73 rgbVec = q.RotateVector(rgbVec).Constrain(0.0f, 255.0f);
74
75 return RGBColor(rgbVec.X, rgbVec.Y, rgbVec.Z);
76}
77
78
79RGBColor RGBColor::InterpolateColors(const RGBColor& a, const RGBColor& b, const float& ratio) {
80 RGBColor c;
81
82 c.R = a.R * (1.0f - ratio) + b.R * ratio;
83 c.G = a.G * (1.0f - ratio) + b.G * ratio;
84 c.B = a.B * (1.0f - ratio) + b.B * ratio;
85
86 return c;
87}
88
90 String r = String(this->R);
91 String g = String(this->G);
92 String b = String(this->B);
93
94 return "[" + r + ", " + g + ", " + b + "]";
95}
Defines the RGBColor class for managing and manipulating RGB color values.
Implements a generic Kalman Filter for 1D data.
static const float MPI
Mathematical constant (3.14159265358979323846...).
Definition Mathematics.h:42
A mathematical construct representing a rotation in 3D space.
Definition Quaternion.h:30
Represents an RGB color and provides methods for manipulation.
Definition RGBColor.h:23
String ToString()
Converts the RGBColor to a string representation.
Definition RGBColor.cpp:89
RGBColor()
Default constructor initializes the color to black (0, 0, 0).
Definition RGBColor.cpp:3
RGBColor HueShift(const float &hueDeg)
Shifts the hue of the color by a specified angle in degrees.
Definition RGBColor.cpp:65
void SetColor(const uint8_t &R, const uint8_t &G, const uint8_t &B)
Sets the RGB values of the color.
Definition RGBColor.cpp:23
RGBColor Scale(const uint8_t &maxBrightness)
Scales the brightness of the color to a maximum value.
Definition RGBColor.cpp:29
static RGBColor InterpolateColors(const RGBColor &a, const RGBColor &b, const float &ratio)
Interpolates between two colors based on a ratio.
Definition RGBColor.cpp:79
uint8_t B
Blue component of the color (0-255).
Definition RGBColor.h:27
uint8_t G
Green component of the color (0-255).
Definition RGBColor.h:26
RGBColor Add(const uint8_t &value)
Adds a value to each RGB component of the color.
Definition RGBColor.cpp:47
uint8_t R
Red component of the color (0-255).
Definition RGBColor.h:25
Represents a 3D vector (X, Y, Z) and provides methods for vector arithmetic.
Definition Vector3D.h:26
float Z
The Z-component of the 3D vector.
Definition Vector3D.h:30
float X
The X-component of the 3D vector.
Definition Vector3D.h:28
float Y
The Y-component of the 3D vector.
Definition Vector3D.h:29