Loading [MathJax]/jax/input/TeX/config.js
ProtoTracer  1.0
Real-time 3D rendering and animation engine
All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros Pages
Oscilloscope.h
Go to the documentation of this file.
1/**
2 * @file Oscilloscope.h
3 * @brief A dynamic oscilloscope material for visualizing audio signals.
4 *
5 * This file defines the Oscilloscope class, which visualizes audio signals in real-time
6 * using a dynamic gradient and configurable physics-based bouncing behavior.
7 *
8 * @date 22/12/2024
9 * @author Coela Can't
10 */
11
12#pragma once
13
14#include "../Material.h" // Base class for material types.
15#include "../Static/GradientMaterial.h" // Include for gradient materials.
16#include "../../../Physics/Utils/BouncePhysics.h" // Include for bounce physics utilities.
17#include "../../../Utils/Filter/MaxFilter.h" // Include for maximum value filtering.
18#include "../../../Utils/Filter/MinFilter.h" // Include for minimum value filtering.
19#include "../../../Utils/Math/Mathematics.h" // Include for mathematical utilities.
20
21/**
22 * @class Oscilloscope
23 * @brief A dynamic oscilloscope material for visualizing audio signals.
24 *
25 * The Oscilloscope class provides real-time visualization of audio signals,
26 * featuring bouncing physics, gradient colors, and customizable attributes such as size,
27 * position, and rotation.
28 */
29class Oscilloscope : public Material {
30private:
31 BouncePhysics* bPhy[128]; ///< Array of BouncePhysics instances for dynamic bouncing behavior.
32 Vector2D size; ///< The size of the oscilloscope visualization.
33 Vector2D offset; ///< The position offset of the visualization.
34 float angle = 0.0f; ///< Rotation angle of the visualization.
35 float hueAngle = 0.0f; ///< Hue angle for color adjustments.
36 float radius = 40.0f; ///< Radius for circular visualization patterns.
37 uint8_t colors; ///< Number of colors in the gradient.
38 float* data; ///< Pointer to the audio sample data.
39 float midPoint = 0.0f; ///< Midpoint for audio data normalization.
40 uint8_t bins = 128; ///< Number of bins for audio data processing.
41
42 MaxFilter<40> maxF = MaxFilter<40>(); ///< Filter for tracking maximum values.
43 MinFilter<40> minF = MinFilter<40>(); ///< Filter for tracking minimum values.
44
45 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.
46 GradientMaterial<6> gM = GradientMaterial<6>(rainbowSpectrum, 1.0f, false); ///< Gradient material for the rainbow spectrum.
47
48 Material* material; ///< Pointer to an additional material for effects.
49
50 float minValue, maxValue; ///< Minimum and maximum values for data scaling.
51
52public:
53 /**
54 * @brief Constructs an Oscilloscope with the specified size and offset.
55 *
56 * @param size The size of the oscilloscope visualization.
57 * @param offset The position offset of the visualization.
58 */
60
61 /**
62 * @brief Destroys the Oscilloscope instance.
63 */
65
66 /**
67 * @brief Sets an additional material for visual effects.
68 *
69 * @param material Pointer to the Material instance.
70 */
72
73 /**
74 * @brief Retrieves the current sample data.
75 *
76 * @return Pointer to the audio sample data array.
77 */
78 float* GetSampleData();
79
80 /**
81 * @brief Sets the size of the oscilloscope visualization.
82 *
83 * @param size The new size as a Vector2D.
84 */
85 void SetSize(Vector2D size);
86
87 /**
88 * @brief Sets the position of the oscilloscope visualization.
89 *
90 * @param offset The new position offset as a Vector2D.
91 */
93
94 /**
95 * @brief Sets the rotation angle of the visualization.
96 *
97 * @param angle The new rotation angle in degrees.
98 */
99 void SetRotation(float angle);
100
101 /**
102 * @brief Sets the hue angle for color adjustments.
103 *
104 * @param hueAngle The new hue angle in degrees.
105 */
106 void SetHueAngle(float hueAngle);
107
108 /**
109 * @brief Updates the oscilloscope visualization based on new audio data.
110 *
111 * @param data Pointer to the audio sample data array.
112 */
113 void Update(float* data);
114
115 /**
116 * @brief Computes the color at a given position in the visualization.
117 *
118 * @param position The position in 3D space.
119 * @param normal The surface normal vector.
120 * @param uvw The texture coordinates.
121 * @return The computed color as an RGBColor.
122 */
123 RGBColor GetRGB(const Vector3D& position, const Vector3D& normal, const Vector3D& uvw) override;
124};
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
Implements a maximum filter over a sliding window.
Definition MaxFilter.h:28
Implements a minimum filter over a sliding window.
Definition MinFilter.h:28
A dynamic oscilloscope material for visualizing audio signals.
MaxFilter< 40 > maxF
Filter for tracking maximum values.
RGBColor rainbowSpectrum[6]
Predefined rainbow colors.
void SetPosition(Vector2D offset)
Sets the position of the oscilloscope visualization.
float radius
Radius for circular visualization patterns.
float * data
Pointer to the audio sample data.
BouncePhysics * bPhy[128]
Array of BouncePhysics instances for dynamic bouncing behavior.
float hueAngle
Hue angle for color adjustments.
float midPoint
Midpoint for audio data normalization.
RGBColor GetRGB(const Vector3D &position, const Vector3D &normal, const Vector3D &uvw) override
Computes the color at a given position in the visualization.
float * GetSampleData()
Retrieves the current sample data.
void SetSize(Vector2D size)
Sets the size of the oscilloscope visualization.
MinFilter< 40 > minF
Filter for tracking minimum values.
~Oscilloscope()
Destroys the Oscilloscope instance.
Vector2D offset
The position offset of the visualization.
float angle
Rotation angle of the visualization.
void Update(float *data)
Updates the oscilloscope visualization based on new audio data.
GradientMaterial< 6 > gM
Gradient material for the rainbow spectrum.
float maxValue
Minimum and maximum values for data scaling.
uint8_t colors
Number of colors in the gradient.
void SetMaterial(Material *material)
Sets an additional material for visual effects.
void SetRotation(float angle)
Sets the rotation angle of the visualization.
Material * material
Pointer to an additional material for 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 oscilloscope visualization.
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