ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
AudioReactiveGradient.h
Go to the documentation of this file.
1/**
2 * @file AudioReactiveGradient.h
3 * @brief A material class for creating an audio-reactive gradient effect.
4 *
5 * This file defines the AudioReactiveGradient class, which creates a gradient effect
6 * that reacts to audio data, with configurable options for size, position, rotation,
7 * hue, and circular patterns.
8 *
9 * @date 22/12/2024
10 * @author Coela Can't
11 */
12
13#pragma once
14
15#include "../Material.h" // Base class for material types.
16#include "../Static/GradientMaterial.h" // Include for static gradient materials.
17#include "../../../Physics/Utils/BouncePhysics.h" // Include for bounce physics utilities.
18#include "../../../Utils/Math/Mathematics.h" // Include for mathematical utilities.
19
20/**
21 * @class AudioReactiveGradient
22 * @brief A material class for creating an audio-reactive gradient effect.
23 *
24 * The AudioReactiveGradient class generates a gradient effect that dynamically reacts
25 * to audio data. It supports features like bouncing effects, circular patterns, and
26 * customizable gradient colors.
27 */
29private:
30 BouncePhysics* bPhy[128]; ///< Array of BouncePhysics instances for handling dynamic bouncing.
31 Vector2D size; ///< The size of the gradient area.
32 Vector2D offset; ///< The offset of the gradient from the origin.
33 float angle = 0.0f; ///< Rotation angle of the gradient.
34 float hueAngle = 0.0f; ///< Hue angle for color adjustments.
35 float radius = 0.0f; ///< Radius for circular gradient patterns.
36 uint8_t colors; ///< Number of colors in the gradient.
37 float* data; ///< Pointer to the audio data array.
38 float bounceData[128]; ///< Processed bounce data for audio reactivity.
39 uint8_t bins = 128; ///< Number of bins for audio data processing.
40 bool bounce = false; ///< Flag indicating if bouncing effects are enabled.
41 bool circular = false; ///< Flag indicating if circular patterns are enabled.
42
43 RGBColor rainbowSpectrum[6] = {RGBColor(255, 0, 0), RGBColor(255, 255, 0), RGBColor(0, 255, 0), RGBColor(0, 255, 255), RGBColor(0, 0, 255), RGBColor(255, 0, 255)}; ///< Predefined rainbow colors.
44 GradientMaterial<6> gM = GradientMaterial<6>(rainbowSpectrum, 1.0f, false); ///< Gradient material for the rainbow spectrum.
45
46 Material* material; ///< Pointer to a secondary material for additional effects.
47
48public:
49 /**
50 * @brief Constructs an AudioReactiveGradient with specified parameters.
51 *
52 * @param size The size of the gradient.
53 * @param offset The offset of the gradient.
54 * @param bounce Enable or disable bouncing effects.
55 * @param circular Enable or disable circular patterns.
56 */
57 AudioReactiveGradient(Vector2D size, Vector2D offset, bool bounce = false, bool circular = false);
58
59 /**
60 * @brief Destroys the AudioReactiveGradient instance.
61 */
63
64 /**
65 * @brief Sets a secondary material for additional effects.
66 *
67 * @param material Pointer to the secondary material.
68 */
70
71 /**
72 * @brief Retrieves the Fourier-transformed audio data.
73 *
74 * @return Pointer to the audio data array.
75 */
76 float* GetFourierData();
77
78 /**
79 * @brief Sets the size of the gradient.
80 *
81 * @param size The new size as a Vector2D.
82 */
83 void SetSize(Vector2D size);
84
85 /**
86 * @brief Sets the position of the gradient.
87 *
88 * @param offset The new position offset as a Vector2D.
89 */
91
92 /**
93 * @brief Sets the rotation angle of the gradient.
94 *
95 * @param angle The new rotation angle in degrees.
96 */
97 void SetRotation(float angle);
98
99 /**
100 * @brief Sets the hue angle for color adjustments.
101 *
102 * @param hueAngle The new hue angle in degrees.
103 */
104 void SetHueAngle(float hueAngle);
105
106 /**
107 * @brief Sets the radius for circular gradient patterns.
108 *
109 * @param radius The new radius value.
110 */
111 void SetRadius(float radius);
112
113 /**
114 * @brief Updates the gradient based on new audio data.
115 *
116 * @param readData Pointer to the audio data array.
117 */
118 void Update(float* readData);
119
120 /**
121 * @brief Retrieves the color of the gradient at a specific position.
122 *
123 * @param position The position in 3D space.
124 * @param normal The surface normal vector.
125 * @param uvw The texture coordinates.
126 * @return The computed color as an RGBColor.
127 */
128 RGBColor GetRGB(const Vector3D& position, const Vector3D& normal, const Vector3D& uvw) override;
129};
A material class for creating an audio-reactive gradient effect.
void SetRadius(float radius)
Sets the radius for circular gradient patterns.
RGBColor rainbowSpectrum[6]
Predefined rainbow colors.
void SetPosition(Vector2D offset)
Sets the position of the gradient.
float radius
Radius for circular gradient patterns.
float bounceData[128]
Processed bounce data for audio reactivity.
float * data
Pointer to the audio data array.
BouncePhysics * bPhy[128]
Array of BouncePhysics instances for handling dynamic bouncing.
float hueAngle
Hue angle for color adjustments.
bool bounce
Flag indicating if bouncing effects are enabled.
float * GetFourierData()
Retrieves the Fourier-transformed audio data.
void Update(float *readData)
Updates the gradient based on new audio data.
RGBColor GetRGB(const Vector3D &position, const Vector3D &normal, const Vector3D &uvw) override
Retrieves the color of the gradient at a specific position.
~AudioReactiveGradient()
Destroys the AudioReactiveGradient instance.
void SetSize(Vector2D size)
Sets the size of the gradient.
Vector2D offset
The offset of the gradient from the origin.
float angle
Rotation angle of the gradient.
bool circular
Flag indicating if circular patterns are enabled.
GradientMaterial< 6 > gM
Gradient material for the rainbow spectrum.
uint8_t colors
Number of colors in the gradient.
void SetMaterial(Material *material)
Sets a secondary material for additional effects.
void SetRotation(float angle)
Sets the rotation angle of the gradient.
Material * material
Pointer to a secondary material for additional effects.
uint8_t bins
Number of bins for audio data processing.
void SetHueAngle(float hueAngle)
Sets the hue angle for color adjustments.
Vector2D size
The size of the gradient area.
Simulates bouncing physics with gravity and velocity damping.
Creates a customizable gradient material for rendering.
Abstract base class for rendering materials.
Definition Material.h:27
Represents an RGB color and provides methods for manipulation.
Definition RGBColor.h:23
Represents a 2D vector (X, Y) and provides methods for vector arithmetic.
Definition Vector2D.h:27
Represents a 3D vector (X, Y, Z) and provides methods for vector arithmetic.
Definition Vector3D.h:26