ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
PhaseOffsetR.cpp
Go to the documentation of this file.
1#include "PhaseOffsetR.h"
2#include "../../Utils/Math/Mathematics.h"
3
4PhaseOffsetR::PhaseOffsetR(uint8_t pixels) : pixels(pixels){}
5
7 if (ratio <= 0.001f) return;
8
9 uint16_t pixelCount = pixelGroup->GetPixelCount();
10 RGBColor* pixelColors = pixelGroup->GetColors();
11 RGBColor* colorBuffer = pixelGroup->GetColorBuffer();
12
13 float rotation = fGenRotation.Update();
14 float range = (pixels - 1) * ratio + 1;
15 float phase120 = 2.0f * Mathematics::MPI * 0.333f;
16 float phase240 = 2.0f * Mathematics::MPI * 0.666f;
17 float mpiR1R = 2.0f * Mathematics::MPI * 8.0f;
18 float mpiR2R = 2.0f * Mathematics::MPI * 8.0f;
19 float mpiR1G = mpiR1R + phase120;
20 float mpiR2G = mpiR2R + phase120;
21 float mpiR1B = mpiR1R + phase240;
22 float mpiR2B = mpiR2R + phase240;
23
24 for (uint16_t i = 0; i < pixelCount; i++) {
25 uint16_t indexR, indexG, indexB;
26 bool validR, validG, validB;
27
28 float coordX = pixelGroup->GetCoordinate(i).X / 10.0f;
29 float coordY = pixelGroup->GetCoordinate(i).Y / 5.0f;
30 float offset1 = fGenPhase1.Update();
31 float offset2 = fGenPhase2.Update();
32 float sineR = sinf(coordX + mpiR1R * offset1) + cosf(coordY + mpiR2R * offset2);
33 float sineG = sinf(coordX + mpiR1G * offset1) + cosf(coordY + mpiR2G * offset2);
34 float sineB = sinf(coordX + mpiR1B * offset1) + cosf(coordY + mpiR2B * offset2);
35
36 uint8_t blurRangeR = Mathematics::Constrain(uint8_t(Mathematics::Map(sineR, -1.0f, 1.0f, 1.0f, range)), uint8_t(1), uint8_t(range));
37 uint8_t blurRangeG = Mathematics::Constrain(uint8_t(Mathematics::Map(sineG, -1.0f, 1.0f, 1.0f, range)), uint8_t(1), uint8_t(range));
38 uint8_t blurRangeB = Mathematics::Constrain(uint8_t(Mathematics::Map(sineB, -1.0f, 1.0f, 1.0f, range)), uint8_t(1), uint8_t(range));
39
40 validR = pixelGroup->GetRadialIndex(i, &indexR, blurRangeR, rotation);
41 validG = pixelGroup->GetRadialIndex(i, &indexG, blurRangeG, rotation + 120.0f);
42 validB = pixelGroup->GetRadialIndex(i, &indexB, blurRangeB, rotation + 240.0f);
43
44 if (validR)
45 colorBuffer[i].R = pixelColors[indexR].R;
46 else
47 colorBuffer[i].R = 0;
48
49 if (validG)
50 colorBuffer[i].G = pixelColors[indexG].G;
51 else
52 colorBuffer[i].G = 0;
53
54 if (validB)
55 colorBuffer[i].B = pixelColors[indexB].B;
56 else
57 colorBuffer[i].B = 0;
58 }
59
60 for (uint16_t i = 0; i < pixelCount; i++) {
61 pixelColors[i].R = colorBuffer[i].R;
62 pixelColors[i].G = colorBuffer[i].G;
63 pixelColors[i].B = colorBuffer[i].B;
64 }
65}
Defines the PhaseOffsetR effect class for applying rotational phase offsets to pixel groups.
float ratio
A scaling ratio used for dynamic effect adjustments.
Definition Effect.h:28
float Update()
Updates and calculates the next value of the waveform.
Interface for managing and interacting with a collection of pixels.
Definition IPixelGroup.h:25
virtual RGBColor * GetColors()=0
Retrieves the array of colors for the pixel group.
virtual RGBColor * GetColorBuffer()=0
Retrieves the color buffer for the pixel group.
virtual Vector2D GetCoordinate(uint16_t count)=0
Retrieves the coordinate of a specific pixel.
virtual uint16_t GetPixelCount()=0
Retrieves the total number of pixels in the group.
virtual bool GetRadialIndex(uint16_t count, uint16_t *index, int pixels, float angle)=0
Retrieves a radial index for a given pixel based on distance and angle.
static const float MPI
Mathematical constant (3.14159265358979323846...).
Definition Mathematics.h:42
static T Map(T value, T inLow, T inMax, T outMin, T outMax)
Maps a value from one range to another.
static T Constrain(T value, T minimum, T maximum)
Constrains a value between minimum and maximum.
FunctionGenerator fGenPhase2
Function generator for the second phase offset.
void ApplyEffect(IPixelGroup *pixelGroup) override
Applies the rotational phase offset effect to the given pixel group.
PhaseOffsetR(uint8_t pixels)
Constructs a PhaseOffsetR effect instance.
FunctionGenerator fGenRotation
Function generator for rotation transformations.
FunctionGenerator fGenPhase1
Function generator for the first phase offset.
const uint8_t pixels
Number of pixels to apply the effect to.
Represents an RGB color and provides methods for manipulation.
Definition RGBColor.h:23
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
uint8_t R
Red component of the color (0-255).
Definition RGBColor.h:25
float X
The X-component of the 2D vector.
Definition Vector2D.h:29
float Y
The Y-component of the 2D vector.
Definition Vector2D.h:30