ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
StripeMaterial.cpp
Go to the documentation of this file.
1#include "SpiralMaterial.h"
2
3SpiralMaterial::SpiralMaterial(uint8_t colorCount, RGBColor* rgbColors, float width, float bend) {
4 this->colorCount = colorCount;
5 this->width = width;
6 this->bend = bend;
7
8 this->rgbColors = new RGBColor[colorCount];
10
11 for (int i = 0; i < colorCount; i++) {
12 this->rgbColors[i] = rgbColors[i];
13 this->baseRGBColors[i] = rgbColors[i];
14 }
15}
16
21
23 this->positionOffset = positionOffset;
24}
25
27 this->rotationOffset = rotationOffset;
28}
29
30void SpiralMaterial::SetRotationAngle(float rotationAngle) {
31 this->rotationAngle = rotationAngle;
32}
33
34void SpiralMaterial::SetWidth(float width) {
35 this->width = width;
36}
37
38void SpiralMaterial::SetBend(float bend) {
39 this->bend = bend;
40}
41
42void SpiralMaterial::HueShift(float hueDeg) {
43 for (int i = 0; i < colorCount; i++) {
44 rgbColors[i] = baseRGBColors[i].HueShift(hueDeg);
45 }
46}
47
48RGBColor SpiralMaterial::GetRGB(const Vector3D& position, const Vector3D& normal, const Vector3D& uvw) {
49 Vector3D positionL = position;
50
51 if (rotationAngle != 0) {
53
54 positionL = positionL - Vector3D(positionOffset.X, positionOffset.Y, 0.0f);
55
56 positionL = temp.RotateVector(positionL);
57 }
58
59 // From x position, fit into bucket ratio
60 // Modulo x value into x range from start position to end position
61
62 float radius = Vector2D(positionL).Magnitude();
63 float angle = atan2(positionL.Y, positionL.X);
64 float ratio = Mathematics::Fract(width * angle / Mathematics::MPI + bend * powf(radius, 0.3f));
65
66 int startBox = floor(ratio * colorCount);
67
68 RGBColor rgb = rgbColors[startBox];
69
70 return rgb;
71}
A material class for generating spiral effects.
Encapsulates a 3D rotation using Euler angles and a specific order of application.
Definition EulerAngles.h:25
static const float MPI
Mathematical constant (3.14159265358979323846...).
Definition Mathematics.h:42
static float Fract(float value)
Returns the fractional part of a floating-point value.
A mathematical construct representing a rotation in 3D space.
Definition Quaternion.h:30
Vector2D RotateVector(const Vector2D &v) const
Rotates a 2D vector by this quaternion, projecting it in 2D.
Represents an RGB color and provides methods for manipulation.
Definition RGBColor.h:23
RGBColor HueShift(const float &hueDeg)
Shifts the hue of the color by a specified angle in degrees.
Definition RGBColor.cpp:65
Handles 3D rotations and conversions between various rotation representations.
Definition Rotation.h:32
Quaternion GetQuaternion()
Gets the quaternion representation of the rotation.
Definition Rotation.cpp:234
void SetPositionOffset(Vector2D positionOffset)
Sets the position offset for the spiral.
void SetRotationAngle(float rotationAngle)
Sets the rotation angle for the spiral.
RGBColor * rgbColors
Array of colors for the spiral.
Vector2D positionOffset
Offset for the position of the spiral.
void HueShift(float hueDeg)
Shifts the hue of the spiral colors.
void SetBend(float bend)
Sets the bending factor of the spiral arms.
uint8_t colorCount
Number of colors in the spiral.
float rotationAngle
Angle to rotate the spiral pattern.
RGBColor GetRGB(const Vector3D &position, const Vector3D &normal, const Vector3D &uvw) override
Retrieves the color for a given position.
void SetRotationOffset(Vector2D rotationOffset)
Sets the rotation offset for the spiral.
RGBColor * baseRGBColors
Backup array for the original colors.
SpiralMaterial(uint8_t colorCount, RGBColor *rgbColors, float width, float bend)
Constructs a SpiralMaterial instance.
void SetWidth(float width)
Sets the width of the spiral arms.
Vector2D rotationOffset
Point around which the spiral rotates.
~SpiralMaterial()
Destructor for SpiralMaterial.
float width
Width of the spiral arms.
float bend
Degree of bending for the spiral arms.
Represents a 2D vector (X, Y) and provides methods for vector arithmetic.
Definition Vector2D.h:27
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
float Magnitude() const
Computes the magnitude (length) of this vector using the formula sqrt(X^2 + Y^2).
Definition Vector2D.cpp:142
Represents a 3D vector (X, Y, Z) and provides methods for vector arithmetic.
Definition Vector3D.h:26
float X
The X-component of the 3D vector.
Definition Vector3D.h:28
float Y
The Y-component of the 3D vector.
Definition Vector3D.h:29
const EulerOrder EulerOrderXYZS
Order: X → Y → Z, static frame.