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