ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
PhaseOffsetX.cpp
Go to the documentation of this file.
1#include "PhaseOffsetX.h"
2#include "../../Utils/Math/Mathematics.h"
3
4PhaseOffsetX::PhaseOffsetX(uint8_t pixels) : pixels(pixels) {}
5
7 if (ratio <= 0.001f) return;
8
9 RGBColor* pixelColors = pixelGroup->GetColors();
10 RGBColor* colorBuffer = pixelGroup->GetColorBuffer();
11
12 for (uint16_t i = 0; i < pixelGroup->GetPixelCount(); i++) {
13 float range = ((pixels - 1) * ratio + 1) / 2.0f;
14 float coordY = pixelGroup->GetCoordinate(i).Y / 10.0f;
15 float mpiR = 2.0f * Mathematics::MPI * fGenPhase.Update();
16 float sineR = sinf(coordY + mpiR * 8.0f);
17 float sineG = sinf(coordY + mpiR * 8.0f + 2.0f * Mathematics::MPI * 0.333f);
18 float sineB = sinf(coordY + mpiR * 8.0f + 2.0f * Mathematics::MPI * 0.666f);
19
20 int8_t blurRangeR = Mathematics::Constrain(int8_t(Mathematics::Map(sineR, -1.0f, 1.0f, -range, range)), int8_t(-range), int8_t(range));
21 int8_t blurRangeG = Mathematics::Constrain(int8_t(Mathematics::Map(sineG, -1.0f, 1.0f, -range, range)), int8_t(-range), int8_t(range));
22 int8_t blurRangeB = Mathematics::Constrain(int8_t(Mathematics::Map(sineB, -1.0f, 1.0f, -range, range)), int8_t(-range), int8_t(range));
23
24 uint16_t indexR = 0, indexG = 0, indexB = 0;
25
26 bool validR = pixelGroup->GetOffsetXIndex(i, &indexR, blurRangeR);
27 bool validG = pixelGroup->GetOffsetXIndex(i, &indexG, blurRangeG);
28 bool validB = pixelGroup->GetOffsetXIndex(i, &indexB, blurRangeB);
29
30 if (validR)
31 colorBuffer[i].R = pixelColors[indexR].R;
32 else
33 colorBuffer[i].R = 0;
34
35 if (validG)
36 colorBuffer[i].G = pixelColors[indexG].G;
37 else
38 colorBuffer[i].G = 0;
39
40 if (validB)
41 colorBuffer[i].B = pixelColors[indexB].B;
42 else
43 colorBuffer[i].B = 0;
44 }
45
46 for (uint16_t i = 0; i < pixelGroup->GetPixelCount(); i++) {
47 pixelColors[i].R = colorBuffer[i].R;
48 pixelColors[i].G = colorBuffer[i].G;
49 pixelColors[i].B = colorBuffer[i].B;
50 }
51}
Defines the PhaseOffsetX effect class for applying horizontal 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 GetOffsetXIndex(uint16_t count, uint16_t *index, int x1)=0
Retrieves an offset X-axis index for a given pixel.
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.
PhaseOffsetX(uint8_t pixels)
Constructs a PhaseOffsetX effect instance.
void ApplyEffect(IPixelGroup *pixelGroup) override
Applies the horizontal phase offset effect to the given pixel group.
FunctionGenerator fGenPhase
Function generator for horizontal phase offsets.
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 Y
The Y-component of the 2D vector.
Definition Vector2D.h:30