ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
Fisheye.cpp
Go to the documentation of this file.
1#include "Fisheye.h"
2
3Fisheye::Fisheye(float amplitude) : amplitude(amplitude) {}
4
6 this->offset = offset;
7}
8
9void Fisheye::SetAmplitude(float amplitude) {
10 this->amplitude = amplitude;
11}
12
14 RGBColor* pixelColors = pixelGroup->GetColors();
15 RGBColor* colorBuffer = pixelGroup->GetColorBuffer();
16 Vector2D mid = pixelGroup->GetCenterCoordinate();
17 float halfWidth = 48.0f; // fGenSize.Update();
18 uint16_t tIndex = 0;
19
21
24
25 for (uint16_t i = 0; i < pixelGroup->GetPixelCount(); i++) {
26 Vector2D pos = pixelGroup->GetCoordinate(i) + offset;
27 Vector2D dif = pos - mid;
28 float distance = fabsf(pos.CalculateEuclideanDistance(mid));
29
30 float r = distance / halfWidth;
31 float theta = atan2(dif.Y, dif.X);
32 float newDistance = powf(r, amplitude);
33
34 int offsetX = (int)(newDistance * cosf(theta));
35 int offsetY = (int)(newDistance * sinf(theta));
36
37 // Use this function to find the index of the pixel at the offset x y pixel
38 if (pixelGroup->GetOffsetXYIndex(i, &tIndex, offsetX, offsetY)) {
39 colorBuffer[i].R = pixelColors[tIndex].R; // copy the current pixel color into the buffer
40 colorBuffer[i].G = pixelColors[tIndex].G;
41 colorBuffer[i].B = pixelColors[tIndex].B;
42 } else {
43 colorBuffer[i].R = 0; // copy the current pixel color into the buffer
44 colorBuffer[i].G = 0;
45 colorBuffer[i].B = 0;
46 }
47 }
48
49 for (uint16_t i = 0; i < pixelGroup->GetPixelCount(); i++) {
50 pixelColors[i].R = colorBuffer[i].R;
51 pixelColors[i].G = colorBuffer[i].G;
52 pixelColors[i].B = colorBuffer[i].B;
53 }
54}
Defines the Fisheye effect class for applying fisheye distortions to pixel groups.
float ratio
A scaling ratio used for dynamic effect adjustments.
Definition Effect.h:28
Fisheye(float amplitude=0.5f)
Constructs a Fisheye effect with a specified amplitude.
Definition Fisheye.cpp:3
FunctionGenerator fGenX
Controls X-axis displacement.
Definition Fisheye.h:31
float amplitude
Amplitude of the distortion effect.
Definition Fisheye.h:29
void SetAmplitude(float amplitude)
Sets the amplitude of the distortion.
Definition Fisheye.cpp:9
void SetPosition(Vector2D offset)
Sets the distortion center offset.
Definition Fisheye.cpp:5
void ApplyEffect(IPixelGroup *pixelGroup) override
Applies the fisheye effect to the given pixel group.
Definition Fisheye.cpp:13
FunctionGenerator fGenWarp
Controls warp effect.
Definition Fisheye.h:33
Vector2D offset
Offset for the fisheye distortion center.
Definition Fisheye.h:28
FunctionGenerator fGenY
Controls Y-axis displacement.
Definition Fisheye.h:32
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 bool GetOffsetXYIndex(uint16_t count, uint16_t *index, int x1, int y1)=0
Retrieves an offset XY-axis index for a given pixel.
virtual uint16_t GetPixelCount()=0
Retrieves the total number of pixels in the group.
virtual Vector2D GetCenterCoordinate()=0
Retrieves the center coordinate of the pixel group.
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
Represents a 2D vector (X, Y) and provides methods for vector arithmetic.
Definition Vector2D.h:27
float CalculateEuclideanDistance(const Vector2D &vector) const
Calculates the Euclidean distance between this vector and another Vector2D.
Definition Vector2D.cpp:150
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