ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
ShiftR.cpp
Go to the documentation of this file.
1#include "ShiftR.h"
2#include "../../Utils/Math/Mathematics.h"
3
4ShiftR::ShiftR(uint8_t pixels) : pixels(pixels) {}
5
7 uint16_t pixelCount = pixelGroup->GetPixelCount();
8 RGBColor* pixelColors = pixelGroup->GetColors();
9 RGBColor* colorBuffer = pixelGroup->GetColorBuffer();
10
11 float rotation = fGenRotation.Update();
12
13 for (uint16_t i = 0; i < pixelCount; i++) {
14 uint16_t indexR, indexG, indexB;
15 bool validR, validG, validB;
16
17 uint8_t range = (uint8_t)Mathematics::Map(ratio, 0.0f, 1.0f, 0.0f, (float)pixels);
18
19 validR = pixelGroup->GetRadialIndex(i, &indexR, range, rotation);
20 validG = pixelGroup->GetRadialIndex(i, &indexG, range, rotation + 120.0f);
21 validB = pixelGroup->GetRadialIndex(i, &indexB, range, rotation + 240.0f);
22
23 if (validR) colorBuffer[i].R = pixelColors[indexR].R;
24 else colorBuffer[i].R = 0;
25
26 if (validG) colorBuffer[i].G = pixelColors[indexG].G;
27 else colorBuffer[i].G = 0;
28
29 if (validB) colorBuffer[i].B = pixelColors[indexB].B;
30 else colorBuffer[i].B = 0;
31 }
32
33 for (uint16_t i = 0; i < pixelCount; i++) {
34 pixelColors[i].R = colorBuffer[i].R;
35 pixelColors[i].G = colorBuffer[i].G;
36 pixelColors[i].B = colorBuffer[i].B;
37 }
38}
Defines the ShiftR effect class for shifting color channels radially.
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 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 T Map(T value, T inLow, T inMax, T outMin, T outMax)
Maps a value from one range to another.
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
ShiftR(uint8_t pixels)
Constructs a ShiftR effect instance.
Definition ShiftR.cpp:4
void ApplyEffect(IPixelGroup *pixelGroup) override
Applies the radial shift effect to the given pixel group.
Definition ShiftR.cpp:6
FunctionGenerator fGenRotation
Function generator for the overall rotation.
Definition ShiftR.h:37
const uint8_t pixels
Number of pixels to consider for the radial effect.
Definition ShiftR.h:28