ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
ProtogenSplitHUB75Project.h
Go to the documentation of this file.
1#pragma once
2
3#include "Animation.h"
4#include "KeyFrameTrack.h"
5#include "EasyEaseAnimator.h"
6#include "../Objects/Background.h"
7#include "../Objects/LEDStripBackground.h"
8#include "../Morph/NukudeFace.h"
9#include "../Render/Scene.h"
10#include "../Signals/FunctionGenerator.h"
11#include "../Menu/SingleButtonMenu.h"
12#include "../Sensors/APDS9960.h"
13
14#include "../Materials/Animated/RainbowNoise.h"
15#include "../Materials/Animated/RainbowSpiral.h"
16#include "../Materials/Animated/SpectrumAnalyzer.h"
17#include "../Materials/Animated/AudioReactiveGradient.h"
18#include "../Materials/Animated/Oscilloscope.h"
19
20#include "../Materials/MaterialAnimator.h"
21
23
24#include "../Signals/FFTVoiceDetection.h"
25
26#include "../Sensors/MicrophoneFourier_MAX9814.h"
27
28#include "../Render/ObjectAlign.h"
29
30class HUB75AnimationSplit : public Animation<3> {
31private:
32 NukudeFace pM;
33 Background background;
34 LEDStripBackground ledStripBackground;
35 EasyEaseAnimator<25> eEA = EasyEaseAnimator<25>(EasyEaseInterpolation::Overshoot, 1.0f, 0.35f);
36
37 //Materials
47
48 RGBColor gradientSpectrum[2] = {RGBColor(255, 0, 0), RGBColor(0, 0, 255)};
50
53
54 SpectrumAnalyzer sA = SpectrumAnalyzer(Vector2D(200, 100), Vector2D(100, 50), true, true);
57
58 //Animation controllers
60
67
71
73
75
76 ObjectAlign objA = ObjectAlign(Vector2D(0.0f, 0.0f), Vector2D(189.0f, 93.0f), Quaternion());
77
78 float offsetFace = 0.0f;
79 float offsetFaceSA = 0.0f;
80 float offsetFaceARG = 0.0f;
81 float offsetFaceOSC = 0.0f;
82 uint8_t offsetFaceInd = 50;
83 uint8_t offsetFaceIndSA = 51;
84 uint8_t offsetFaceIndARG = 52;
85 uint8_t offsetFaceIndOSC = 53;
86 bool mirror = false;
87
89 eEA.AddParameter(pM.GetMorphWeightReference(NukudeFace::Anger), NukudeFace::Anger, 15, 0.0f, 1.0f);
90 eEA.AddParameter(pM.GetMorphWeightReference(NukudeFace::Sadness), NukudeFace::Sadness, 50, 0.0f, 1.0f);
91 eEA.AddParameter(pM.GetMorphWeightReference(NukudeFace::Surprised), NukudeFace::Surprised, 10, 0.0f, 1.0f);
92 eEA.AddParameter(pM.GetMorphWeightReference(NukudeFace::Doubt), NukudeFace::Doubt, 25, 0.0f, 1.0f);
93 eEA.AddParameter(pM.GetMorphWeightReference(NukudeFace::Frown), NukudeFace::Frown, 45, 0.0f, 1.0f);
94 eEA.AddParameter(pM.GetMorphWeightReference(NukudeFace::LookUp), NukudeFace::LookUp, 30, 0.0f, 1.0f);
95 eEA.AddParameter(pM.GetMorphWeightReference(NukudeFace::LookDown), NukudeFace::LookDown, 30, 0.0f, 1.0f);
96
97 eEA.AddParameter(pM.GetMorphWeightReference(NukudeFace::vrc_v_ee), NukudeFace::vrc_v_ee, 2, 0.0f, 1.0f);
98 eEA.AddParameter(pM.GetMorphWeightReference(NukudeFace::vrc_v_ih), NukudeFace::vrc_v_ih, 2, 0.0f, 1.0f);
99 eEA.AddParameter(pM.GetMorphWeightReference(NukudeFace::vrc_v_dd), NukudeFace::vrc_v_dd, 2, 0.0f, 1.0f);
100 eEA.AddParameter(pM.GetMorphWeightReference(NukudeFace::vrc_v_rr), NukudeFace::vrc_v_rr, 2, 0.0f, 1.0f);
101 eEA.AddParameter(pM.GetMorphWeightReference(NukudeFace::vrc_v_ch), NukudeFace::vrc_v_ch, 2, 0.0f, 1.0f);
102 eEA.AddParameter(pM.GetMorphWeightReference(NukudeFace::vrc_v_aa), NukudeFace::vrc_v_aa, 2, 0.0f, 1.0f);
103 eEA.AddParameter(pM.GetMorphWeightReference(NukudeFace::vrc_v_oh), NukudeFace::vrc_v_oh, 2, 0.0f, 1.0f);
104 eEA.AddParameter(pM.GetMorphWeightReference(NukudeFace::vrc_v_ss), NukudeFace::vrc_v_ss, 2, 0.0f, 1.0f);
105
106 eEA.AddParameter(pM.GetMorphWeightReference(NukudeFace::HideBlush), NukudeFace::HideBlush, 30, 1.0f, 0.0f);
107 eEA.AddParameter(pM.GetMorphWeightReference(NukudeFace::HideBlush), NukudeFace::HideBlush, 30, 1.0f, 0.0f);
108
109 eEA.AddParameter(&offsetFace, offsetFaceInd, 40, 0.0f, 1.0f);
110 eEA.AddParameter(&offsetFaceSA, offsetFaceIndSA, 40, 0.0f, 1.0f);
113 }
114
116 blink.AddParameter(pM.GetMorphWeightReference(NukudeFace::Blink));
117 }
118
120 eEA.SetInterpolationMethod(NukudeFace::HideBlush, EasyEaseInterpolation::Cosine);
121 eEA.SetInterpolationMethod(NukudeFace::Sadness, EasyEaseInterpolation::Cosine);
122
123 eEA.SetInterpolationMethod(NukudeFace::vrc_v_ee, EasyEaseInterpolation::Linear);
124 eEA.SetInterpolationMethod(NukudeFace::vrc_v_ih, EasyEaseInterpolation::Linear);
125 eEA.SetInterpolationMethod(NukudeFace::vrc_v_dd, EasyEaseInterpolation::Linear);
126 eEA.SetInterpolationMethod(NukudeFace::vrc_v_rr, EasyEaseInterpolation::Linear);
127 eEA.SetInterpolationMethod(NukudeFace::vrc_v_ch, EasyEaseInterpolation::Linear);
128 eEA.SetInterpolationMethod(NukudeFace::vrc_v_aa, EasyEaseInterpolation::Linear);
129 eEA.SetInterpolationMethod(NukudeFace::vrc_v_oh, EasyEaseInterpolation::Linear);
130 eEA.SetInterpolationMethod(NukudeFace::vrc_v_ss, EasyEaseInterpolation::Linear);
131 }
132
150
152 blink.Update();
153 }
154
155 void Default(){}
156
157 void Angry(){
158 eEA.AddParameterFrame(NukudeFace::Anger, 1.0f);
160 }
161
162 void Sad(){
163 eEA.AddParameterFrame(NukudeFace::Sadness, 1.0f);
164 eEA.AddParameterFrame(NukudeFace::Frown, 1.0f);
166 }
167
168 void Surprised(){
169 eEA.AddParameterFrame(NukudeFace::Surprised, 1.0f);
170 eEA.AddParameterFrame(NukudeFace::HideBlush, 0.0f);
172 }
173
174 void Doubt(){
175 eEA.AddParameterFrame(NukudeFace::Doubt, 1.0f);
176 }
177
178 void Frown(){
179 eEA.AddParameterFrame(NukudeFace::Frown, 1.0f);
180 }
181
182 void LookUp(){
183 eEA.AddParameterFrame(NukudeFace::LookUp, 1.0f);
184 }
185
186 void LookDown(){
187 eEA.AddParameterFrame(NukudeFace::LookDown, 1.0f);
188 }
189
196
203
210
213 eEA.AddParameterFrame(NukudeFace::vrc_v_ss, MicrophoneFourierIT::GetCurrentMagnitude() / 2.0f);
214
215 if(MicrophoneFourierIT::GetCurrentMagnitude() > 0.05f){
216 voiceDetection.Update(MicrophoneFourierIT::GetFourierFiltered(), MicrophoneFourierIT::GetSampleRate());
217
225 }
226 }
227 }
228
230 switch(Menu::GetFaceColor()){
231 case 1: materialAnimator.AddMaterialFrame(redMaterial, 0.8f); break;
233 case 3: materialAnimator.AddMaterialFrame(whiteMaterial, 0.8f); break;
234 case 4: materialAnimator.AddMaterialFrame(greenMaterial, 0.8f); break;
235 case 5: materialAnimator.AddMaterialFrame(blueMaterial, 0.8f); break;
238 case 8: materialAnimator.AddMaterialFrame(rainbowSpiral, 0.8f); break;
239 case 9: materialAnimator.AddMaterialFrame(rainbowNoise, 0.8f); break;
240 default: break;
241 }
242 }
243
244public:
246 scene.AddObject(pM.GetObject());
247 scene.AddObject(background.GetObject());
248 scene.AddObject(ledStripBackground.GetObject());
249
250 LinkEasyEase();
252
254
256
257 pM.GetObject()->SetMaterial(&materialAnimator);
258 background.GetObject()->SetMaterial(&backgroundMaterial);
259 ledStripBackground.GetObject()->SetMaterial(&materialAnimator);
260
262 objA.SetMirrorX(true);
263 }
264
265 void Initialize() override {
266 boop.Initialize(5);
267
268 MicrophoneFourierIT::Initialize(A0, 8000, 50.0f, 120.0f);//8KHz sample rate, 50dB min, 120dB max
269 Menu::Initialize(9, 20, 500);//7 is number of faces
270 }
271
272
273 void FadeIn(float stepRatio) override {}
274 void FadeOut(float stepRatio) override {}
275
277 return pM.GetObject();
278 }
279
281 this->mirror = mirror;
282 }
283
284 void Update(float ratio) override {
285 if(!mirror){
286 gradientSpectrum[0] = RGBColor(255, 0, 0).HueShift(Menu::GetHueF() * 36);
287 gradientSpectrum[1] = RGBColor(255, 0, 0).HueShift(Menu::GetHueB() * 36);
288
291
292 pM.Reset();
293
294 float xOffset = fGenMatXMove.Update();
295 float yOffset = fGenMatYMove.Update();
296
297 Menu::Update(ratio);
298
300
301 bool isBooped = Menu::UseBoopSensor() ? boop.isBooped() : 0;
302 uint8_t mode = Menu::GetFaceState();//change by button press
303
304 MicrophoneFourierIT::Update();
305 sA.SetHueAngle(ratio * 360.0f * 4.0f);
308
309 aRG.SetRadius((xOffset + 2.0f) * 2.0f + 25.0f);
310 aRG.SetSize(Vector2D((xOffset + 2.0f) * 10.0f + 50.0f, (xOffset + 2.0f) * 10.0f + 50.0f));
311 aRG.SetHueAngle(ratio * 360.0f * 8.0f);
312 aRG.SetRotation(ratio * 360.0f * 2.0f);
313 aRG.SetPosition(Vector2D(80.0f + xOffset * 4.0f, 48.0f + yOffset * 4.0f));
314
315 oSC.SetSize(Vector2D(200.0f, 100.0f));
316 oSC.SetHueAngle(ratio * 360.0f * 8.0f);
317 oSC.SetPosition(Vector2D(100.0f, 50.0f));
318
320
321 if (isBooped && mode != 6){
322 Surprised();
323 }
324 else{
325 if (mode == 0) Default();
326 else if (mode == 1) Angry();
327 else if (mode == 2) Doubt();
328 else if (mode == 3) Frown();
329 else if (mode == 4) LookUp();
330 else if (mode == 5) Sad();
331 else if (mode == 6) {
332 aRG.Update(MicrophoneFourierIT::GetFourierFiltered());
334 }
335 else if (mode == 7){
336 oSC.Update(MicrophoneFourierIT::GetSamples());
338 }
339 else {
340 sA.Update(MicrophoneFourierIT::GetFourierFiltered());
342 }
343 }
344
346
347 pM.SetMorphWeight(NukudeFace::BiggerNose, 1.0f);
348 pM.SetMorphWeight(NukudeFace::MoveEye, 1.0f);
349
350 eEA.Update();
351 pM.Update();
352
353 rainbowNoise.Update(ratio);
354 rainbowSpiral.Update(ratio);
357
358 uint8_t faceSize = Menu::GetFaceSize();
359 float scale = Menu::ShowMenu() * 0.6f + 0.4f;
360 float faceSizeOffset = faceSize * 8.0f;
361
363 objA.SetEdgeMargin(2.0f);
364 objA.SetCameraMax(Vector2D(110.0f + faceSizeOffset, 93.0f - 93.0f * offsetFace).Multiply(scale));
365
366 objA.AlignObjects(scene.GetObjects(), 1);
367
368 pM.GetObject()->GetTransform()->SetPosition(Vector3D(xOffset, yOffset, 0.0f));
369 pM.GetObject()->UpdateTransform();
370 }
371 else{
372 gradientSpectrum[0] = RGBColor(255, 0, 0).HueShift(Menu::GetHueF() * 36);
373 gradientSpectrum[1] = RGBColor(255, 0, 0).HueShift(Menu::GetHueB() * 36);
374
377 }
378 }
379};
Declares the BlinkTrack template class for animating eye blinking.
Declares the EasyEaseAnimator template class for advanced animation easing.
Declares the KeyFrameTrack template class for managing keyframe-based animations.
A class for managing the Adafruit APDS9960 sensor.
Definition APDS9960.h:27
static bool Initialize(uint8_t threshold)
Initializes the APDS9960 sensor.
Definition APDS9960.cpp:14
static bool isBooped()
Checks if the sensor is "booped" (close proximity detected).
Definition APDS9960.cpp:43
void AddParameter(float *parameter)
Adds a parameter to the animation track.
float Update()
Updates the animation track and returns the current parameter value.
A material class for creating an audio-reactive gradient effect.
void SetRadius(float radius)
Sets the radius for circular gradient patterns.
void SetPosition(Vector2D offset)
Sets the position of the gradient.
void Update(float *readData)
Updates the gradient based on new audio data.
void SetSize(Vector2D size)
Sets the size of the gradient.
void SetRotation(float angle)
Sets the rotation angle of the gradient.
void SetHueAngle(float hueAngle)
Sets the hue angle for color adjustments.
A template class for animating eye blinking using keyframes.
Definition BlinkTrack.h:27
A template class for implementing advanced animation easing.
void AddParameterFrame(uint16_t dictionaryValue, float value) override
Adds a single frame value for a parameter.
void Update() override
Updates the animator, advancing all animations.
void SetInterpolationMethod(uint16_t dictionaryValue, InterpolationMethod interpMethod) override
Sets the interpolation method for a specific parameter.
void AddParameter(float *parameter, uint16_t dictionaryValue, uint16_t frames, float basis, float goal) override
Adds a parameter to the animator.
Detects visemes based on FFT voice analysis.
float GetViseme(MouthShape viseme)
Retrieves the probability of a specific viseme.
void Update(float *peaks, float maxFrequency)
Updates the viseme probabilities based on new FFT data.
A class to generate various waveform functions with customizable parameters.
@ Sine
Sine waveform.
@ Triangle
Triangle waveform.
float Update()
Updates and calculates the next value of the waveform.
Creates a customizable gradient material for rendering.
void UpdateGradient(RGBColor *rgbColors)
Updates the colors of the gradient.
void UpdateRGB()
Updates the RGB colors in the gradient.
EasyEaseAnimator< 25 > eEA
LEDStripBackground ledStripBackground
GradientMaterial< 2 > gradientMat
void FadeIn(float stepRatio) override
void FadeOut(float stepRatio) override
MaterialAnimator< 10 > materialAnimator
void Update(float ratio) override
FFTVoiceDetection< 128 > voiceDetection
MaterialAnimator< 4 > backgroundMaterial
AudioReactiveGradient aRG
Animates transitions and blends between multiple materials.
void AddMaterial(Material::Method method, Material *material, uint16_t frames, float minOpacity, float maxOpacity)
Adds a material to the animation with specified properties.
void SetBaseMaterial(Material::Method method, Material *material)
Sets the base material for the animation.
void AddMaterialFrame(Material &material, float opacity)
Adds a specific frame for a material in the animation.
void Update()
Updates the animator, advancing the transitions.
@ Add
Adds colors together.
Definition Material.h:35
@ Replace
Replaces the base color.
Definition Material.h:44
static uint8_t GetFaceState()
Retrieves the current face state. In hardware mode, it is read from the MenuHandler.
Definition Menu.cpp:381
static uint8_t GetFaceColor()
Gets the current face color index.
Definition Menu.cpp:453
static float ShowMenu()
Returns how much of the menu is shown, typically normalized (0.0 to 1.0).
Definition Menu.cpp:494
static Material * GetMaterial()
Provides a pointer to the material used for rendering the menu text.
Definition Menu.cpp:155
static uint8_t MirrorSpectrumAnalyzer()
Checks if the spectrum analyzer mirroring is toggled on or off.
Definition Menu.cpp:435
static uint8_t GetFaceSize()
Gets the current face size.
Definition Menu.cpp:444
static void Initialize(uint8_t faceCount, uint8_t pin, uint16_t holdingTime, Vector2D size=Vector2D(240, 50))
Initializes the Menu using a face count, input pin, holding time, and size.
Definition Menu.cpp:102
static uint8_t GetHueF()
Gets the front hue value.
Definition Menu.cpp:462
static uint8_t UseMicrophone()
Checks if the microphone usage is toggled on or off.
Definition Menu.cpp:408
static uint8_t UseBoopSensor()
Checks if the boop sensor usage is toggled on or off.
Definition Menu.cpp:426
static void Update(float ratio)
Updates the menu each frame, handling transitions, wiggle effects, and text generation.
Definition Menu.cpp:208
static uint8_t GetHueB()
Gets the back hue value.
Definition Menu.cpp:471
Represents a 3D object with geometry, material, and transformation data.
Definition Object3D.h:28
Handles aligning and transforming 3D objects to fit within specified 2D camera bounds.
Definition ObjectAlign.h:24
void SetEdgeMargin(float edgeMargin)
Sets the margin to keep from the edges when aligning objects.
@ Stretch
Attempt to scale the object(s) to fill the entire area.
Definition ObjectAlign.h:43
void SetJustification(Justification jst)
Sets the justification mode for alignment.
void SetPlaneOffsetAngle(float offsetPlaneAngle)
Sets the additional rotation offset (plane offset angle), in degrees or radians, that will be applied...
void SetCameraMax(Vector2D camMax)
Updates the maximum bounds for the 2D camera region.
void AlignObjects(Object3D **objs, uint8_t numObjects)
Aligns multiple objects within the camera bounds, including scale factors.
void SetMirrorX(bool mirrorX)
Enables or disables mirroring along the X-axis for the aligned objects.
A dynamic oscilloscope material for visualizing audio signals.
void SetPosition(Vector2D offset)
Sets the position of the oscilloscope visualization.
void SetSize(Vector2D size)
Sets the size of the oscilloscope visualization.
void Update(float *data)
Updates the oscilloscope visualization based on new audio data.
void SetHueAngle(float hueAngle)
Sets the hue angle for color adjustments.
A mathematical construct representing a rotation in 3D space.
Definition Quaternion.h:30
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
A dynamic material that creates a rainbow effect using simplex noise.
void Update(float ratio)
Updates the material animation based on the time ratio.
A dynamic material creating a colorful rainbow spiral animation.
void Update(float ratio)
Updates the material animation based on the time ratio.
A material that applies a single, solid RGB color to surfaces.
A material that visualizes audio data as a spectrum.
void SetMirrorYState(bool state)
Sets the mirroring state for the visualization.
void Update(float *readData)
Updates the spectrum visualization with new audio data.
void SetFlipYState(bool state)
Sets the flipping state for the visualization.
void SetHueAngle(float hueAngle)
Sets the hue adjustment angle for the spectrum colors.
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
@ ER
Mouth shape corresponding to the "ER" sound.
@ OO
Mouth shape corresponding to the "OO" sound.
@ AH
Mouth shape corresponding to the "AH" sound.
@ UH
Mouth shape corresponding to the "UH" sound.
@ AR
Mouth shape corresponding to the "AR" sound.
@ EE
Mouth shape corresponding to the "EE" sound.