ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
BasilGardenAnimation.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/Commissions/BasilGarden.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
22#include "../AnimationTracks/BlinkTrack.h"
23
24#include "../../Signals/FFTVoiceDetection.h"
25
26#include "../../Sensors/MicrophoneFourier_MAX9814.h"
27
28#include "../../Render/ObjectAlign.h"
29
30#include "../../Screenspace/GlitchX.h"
31#include "../../Screenspace/Fisheye.h"
32#include "../../Screenspace/HorizontalBlur.h"
33#include "../../Screenspace/PhaseOffsetX.h"
34#include "../../Screenspace/PhaseOffsetY.h"
35#include "../../Screenspace/PhaseOffsetR.h"
36#include "../../Screenspace/Magnet.h"
37#include "../../Screenspace/Overflow.h"
38#include "../../Screenspace/RadialBlur.h"
39#include "../../Screenspace/ShiftR.h"
40#include "../../Screenspace/VerticalBlur.h"
41
42class BasilGardenAnimation : public Animation<3> {
43private:
44 static const uint8_t faceCount = 9;
45 BasilGarden pM;
46 Background background;
47 LEDStripBackground ledStripBackground;
48 EasyEaseAnimator<25> eEA = EasyEaseAnimator<25>(EasyEaseInterpolation::Overshoot, 1.0f, 0.35f);
49
50 //Materials
60
61 RGBColor gradientSpectrum[2] = {RGBColor(252, 145, 34), RGBColor(252, 80, 15)};
63
66
67 SpectrumAnalyzer sA = SpectrumAnalyzer(Vector2D(200, 100), Vector2D(100, 50), true, true);
70
71 //Animation controllers
73
80
84
86
88
90
91 ObjectAlign objA = ObjectAlign(Vector2D(0.0f, 0.0f), Vector2D(189.0f, 93.0f), Quaternion());
92
104
105 float offsetFace = 0.0f;
106 float offsetFaceSA = 0.0f;
107 float offsetFaceARG = 0.0f;
108 float offsetFaceOSC = 0.0f;
109 uint8_t offsetFaceInd = 50;
110 uint8_t offsetFaceIndSA = 51;
111 uint8_t offsetFaceIndARG = 52;
112 uint8_t offsetFaceIndOSC = 53;
113
115 eEA.AddParameter(pM.GetMorphWeightReference(BasilGarden::Angry), BasilGarden::Angry, 15, 0.0f, 1.0f);
116 eEA.AddParameter(pM.GetMorphWeightReference(BasilGarden::Sad), BasilGarden::Sad, 50, 0.0f, 1.0f);
117 eEA.AddParameter(pM.GetMorphWeightReference(BasilGarden::Rage), BasilGarden::Rage, 10, 0.0f, 1.0f);
118 eEA.AddParameter(pM.GetMorphWeightReference(BasilGarden::Smirk), BasilGarden::Smirk, 25, 0.0f, 1.0f);
119 eEA.AddParameter(pM.GetMorphWeightReference(BasilGarden::Disappointed), BasilGarden::Disappointed, 45, 0.0f, 1.0f);
120 eEA.AddParameter(pM.GetMorphWeightReference(BasilGarden::Grimace), BasilGarden::Grimace, 30, 0.0f, 1.0f);
121 eEA.AddParameter(pM.GetMorphWeightReference(BasilGarden::Whoops), BasilGarden::Whoops, 30, 0.0f, 1.0f);
122 eEA.AddParameter(pM.GetMorphWeightReference(BasilGarden::Crabby), BasilGarden::Crabby, 30, 0.0f, 1.0f);
123 eEA.AddParameter(pM.GetMorphWeightReference(BasilGarden::Default), BasilGarden::Default, 30, 0.0f, 1.0f);
124 eEA.AddParameter(pM.GetMorphWeightReference(BasilGarden::ForReal), BasilGarden::ForReal, 30, 0.0f, 1.0f);
125
126 eEA.AddParameter(pM.GetMorphWeightReference(BasilGarden::vrc_v_ee), BasilGarden::vrc_v_ee, 2, 0.0f, 1.0f);
127 eEA.AddParameter(pM.GetMorphWeightReference(BasilGarden::vrc_v_ih), BasilGarden::vrc_v_ih, 2, 0.0f, 1.0f);
128 eEA.AddParameter(pM.GetMorphWeightReference(BasilGarden::vrc_v_dd), BasilGarden::vrc_v_dd, 2, 0.0f, 1.0f);
129 eEA.AddParameter(pM.GetMorphWeightReference(BasilGarden::vrc_v_rr), BasilGarden::vrc_v_rr, 2, 0.0f, 1.0f);
130 eEA.AddParameter(pM.GetMorphWeightReference(BasilGarden::vrc_v_ch), BasilGarden::vrc_v_ch, 2, 0.0f, 1.0f);
131 eEA.AddParameter(pM.GetMorphWeightReference(BasilGarden::vrc_v_aa), BasilGarden::vrc_v_aa, 2, 0.0f, 1.0f);
132 eEA.AddParameter(pM.GetMorphWeightReference(BasilGarden::vrc_v_oh), BasilGarden::vrc_v_oh, 2, 0.0f, 1.0f);
133 eEA.AddParameter(pM.GetMorphWeightReference(BasilGarden::vrc_v_ss), BasilGarden::vrc_v_ss, 2, 0.0f, 1.0f);
134
135 eEA.AddParameter(&offsetFace, offsetFaceInd, 40, 0.0f, 1.0f);
136 eEA.AddParameter(&offsetFaceSA, offsetFaceIndSA, 40, 0.0f, 1.0f);
139 }
140
142 blink.AddParameter(pM.GetMorphWeightReference(BasilGarden::Blink));
143 }
144
146 eEA.SetInterpolationMethod(BasilGarden::Sad, EasyEaseInterpolation::Cosine);
147
148 eEA.SetInterpolationMethod(BasilGarden::vrc_v_ee, EasyEaseInterpolation::Linear);
149 eEA.SetInterpolationMethod(BasilGarden::vrc_v_ih, EasyEaseInterpolation::Linear);
150 eEA.SetInterpolationMethod(BasilGarden::vrc_v_dd, EasyEaseInterpolation::Linear);
151 eEA.SetInterpolationMethod(BasilGarden::vrc_v_rr, EasyEaseInterpolation::Linear);
152 eEA.SetInterpolationMethod(BasilGarden::vrc_v_ch, EasyEaseInterpolation::Linear);
153 eEA.SetInterpolationMethod(BasilGarden::vrc_v_aa, EasyEaseInterpolation::Linear);
154 eEA.SetInterpolationMethod(BasilGarden::vrc_v_oh, EasyEaseInterpolation::Linear);
155 eEA.SetInterpolationMethod(BasilGarden::vrc_v_ss, EasyEaseInterpolation::Linear);
156 }
157
175
177 blink.Update();
178 }
179
180 void Default(){
181 scene.DisableEffect();
182 eEA.AddParameterFrame(BasilGarden::Default, 1.0f);
183 }
184
185 void Angry(){
186 eEA.AddParameterFrame(BasilGarden::Angry, 1.0f);
188 }
189
190 void Sad(){
191 eEA.AddParameterFrame(BasilGarden::Sad, 1.0f);
193 }
194
195 void Rage(){
196 scene.SetEffect(&glitchX);
197 scene.DisableEffect();
198
199 eEA.AddParameterFrame(BasilGarden::Rage, 1.0f);
201 }
202
203 void Smirk(){
204 eEA.AddParameterFrame(BasilGarden::Smirk, 1.0f);
205 }
206
208 eEA.AddParameterFrame(BasilGarden::Disappointed, 1.0f);
209 }
210
211 void Grimace(){
212 eEA.AddParameterFrame(BasilGarden::Grimace, 1.0f);
213 }
214
215 void Whoops(){
216 eEA.AddParameterFrame(BasilGarden::Whoops, 1.0f);
217 }
218
219 void Crabby(){
220 eEA.AddParameterFrame(BasilGarden::Crabby, 1.0f);
221 }
222
223 void ForReal(){
224 eEA.AddParameterFrame(BasilGarden::ForReal, 1.0f);
226 }
227
234
241
248
251 eEA.AddParameterFrame(BasilGarden::vrc_v_ss, MicrophoneFourierIT::GetCurrentMagnitude() / 2.0f);
252
253 if(MicrophoneFourierIT::GetCurrentMagnitude() > 0.05f){
254 voiceDetection.Update(MicrophoneFourierIT::GetFourierFiltered(), MicrophoneFourierIT::GetSampleRate());
255
263 }
264 }
265 }
266
268 switch(Menu::GetFaceColor()){
269 case 1: materialAnimator.AddMaterialFrame(redMaterial, 0.8f); break;
271 case 3: materialAnimator.AddMaterialFrame(whiteMaterial, 0.8f); break;
272 case 4: materialAnimator.AddMaterialFrame(greenMaterial, 0.8f); break;
273 case 5: materialAnimator.AddMaterialFrame(blueMaterial, 0.8f); break;
276 case 8: materialAnimator.AddMaterialFrame(rainbowSpiral, 0.8f); break;
277 case 9: materialAnimator.AddMaterialFrame(rainbowNoise, 0.8f); break;
278 default: break;
279 }
280 }
281
282public:
284 scene.AddObject(pM.GetObject());
285 scene.AddObject(background.GetObject());
286 scene.AddObject(ledStripBackground.GetObject());
287
288 LinkEasyEase();
290
292
294
295 pM.GetObject()->SetMaterial(&materialAnimator);
296 background.GetObject()->SetMaterial(&backgroundMaterial);
297 ledStripBackground.GetObject()->SetMaterial(&materialAnimator);
298
299 boop.Initialize(5);
300
301 MicrophoneFourierIT::Initialize(A2, 8000, 50.0f, 120.0f);//8KHz sample rate, 50dB min, 120dB max
302 //Menu::Initialize(9);//NeoTrellis
303 Menu::Initialize(11, 20, 500);//12 is number of faces
304
306 objA.SetMirrorX(true);
307 }
308
311 };
312
313 uint8_t GetBrightness(){
314 return Menu::GetBrightness();
315 };
316
317 void FadeIn(float stepRatio) override {}
318 void FadeOut(float stepRatio) override {}
319
321 return pM.GetObject();
322 }
323
324 void Update(float ratio) override {
325 pM.Reset();
326
327 float xOffset = fGenMatXMove.Update();
328 float yOffset = fGenMatYMove.Update();
329
330 Menu::Update(ratio);
331
332 //Menu::SetSize(Vector2D(280, 60));
333 //Menu::SetPositionOffset(Vector2D(0.0f, -30.0f * yOffset));
334
335 //glitchX.SetRatio(fGenBlur.Update());
336 magnet.SetRatio(ratio);
345
347
348 bool isBooped = Menu::UseBoopSensor() ? boop.isBooped() : 0;
349 uint8_t mode = Menu::GetFaceState();//change by button press
350
351 MicrophoneFourierIT::Update();
352 sA.SetHueAngle(ratio * 360.0f * 4.0f);
355
356 aRG.SetRadius((xOffset + 2.0f) * 2.0f + 25.0f);
357 aRG.SetSize(Vector2D((xOffset + 2.0f) * 10.0f + 50.0f, (xOffset + 2.0f) * 10.0f + 50.0f));
358 aRG.SetHueAngle(ratio * 360.0f * 8.0f);
359 aRG.SetRotation(ratio * 360.0f * 2.0f);
360 aRG.SetPosition(Vector2D(80.0f + xOffset * 4.0f, 48.0f + yOffset * 4.0f));
361
362 oSC.SetSize(Vector2D(200.0f, 100.0f));
363 oSC.SetHueAngle(ratio * 360.0f * 8.0f);
364 oSC.SetPosition(Vector2D(100.0f, 50.0f));
365
366 voiceDetection.SetThreshold(map(Menu::GetMicLevel(), 0, 10, 1000, 50));
367
369
370 if (isBooped && mode != 6){
371 ForReal();
372 }
373 else{
374 if (mode == 0) Default();
375 else if (mode == 1) Sad();
376 else if (mode == 2) Grimace();
377 else if (mode == 3) Disappointed();
378 else if (mode == 4) Angry();
379 else if (mode == 5) Whoops();
380 else if (mode == 6) Crabby();
381 else if (mode == 7) Rage();
382 else if (mode == 8) {
383 aRG.Update(MicrophoneFourierIT::GetFourierFiltered());
385 }
386 else if (mode == 9){
387 oSC.Update(MicrophoneFourierIT::GetSamples());
389 }
390 else {
391 sA.Update(MicrophoneFourierIT::GetFourierFiltered());
393 }
394 }
395
397
398 eEA.Update();
399 pM.Update();
400
401 //phaseR.SetRatio(eEA.GetValue(BasilGarden::Rage));
402 glitchX.SetRatio(eEA.GetValue(BasilGarden::Rage));
403
404 rainbowNoise.Update(ratio);
405 rainbowSpiral.Update(ratio);
408
409 uint8_t faceSize = Menu::GetFaceSize();
410 float scale = Menu::ShowMenu() * 0.6f + 0.4f;
411 float faceSizeOffset = faceSize * 8.0f;
412
414 objA.SetEdgeMargin(2.0f);
415 objA.SetCameraMax(Vector2D(110.0f + faceSizeOffset, 93.0f - 93.0f * offsetFace).Multiply(scale));
416
417 objA.AlignObjects(scene.GetObjects(), 1);
418
419 pM.GetObject()->GetTransform()->SetPosition(Vector3D(xOffset, yOffset, 0.0f));
420 pM.GetObject()->UpdateTransform();
421 }
422};
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.
FunctionGenerator fGenMatHue
FunctionGenerator fGenMatYMove
FunctionGenerator fGenMatRMenu
EasyEaseAnimator< 25 > eEA
LEDStripBackground ledStripBackground
GradientMaterial< 2 > gradientMat
FunctionGenerator fGenMatPos
FunctionGenerator fGenScale
FunctionGenerator fGenRotation
FunctionGenerator fGenMatXMenu
void FadeIn(float stepRatio) override
void FadeOut(float stepRatio) override
FunctionGenerator fGenMatYMenu
FunctionGenerator fGenMatXMove
MaterialAnimator< 10 > materialAnimator
void Update(float ratio) override
static const uint8_t faceCount
FFTVoiceDetection< 128 > voiceDetection
FunctionGenerator fGenBlur
MaterialAnimator< 4 > backgroundMaterial
AudioReactiveGradient aRG
A template class for animating eye blinking using keyframes.
Definition BlinkTrack.h:27
A template class for implementing advanced animation easing.
float GetValue(uint16_t dictionaryValue) override
Gets the current value of a parameter.
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.
void SetRatio(float ratio)
Sets the scaling ratio for the effect.
Definition Effect.cpp:5
Detects visemes based on FFT voice analysis.
float GetViseme(MouthShape viseme)
Retrieves the probability of a specific viseme.
void SetThreshold(float threshold)
Sets the threshold for formant calculations.
void Update(float *peaks, float maxFrequency)
Updates the viseme probabilities based on new FFT data.
Implements a fisheye distortion effect for pixel groups.
Definition Fisheye.h:26
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.
Implements a glitch effect along the X-axis for pixel groups.
Definition GlitchX.h:26
Creates a customizable gradient material for rendering.
Implements a horizontal blur effect for pixel groups.
Implements a magnetic distortion effect for pixel groups.
Definition Magnet.h:25
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 uint8_t GetMicLevel()
Gets the current microphone level.
Definition Menu.cpp:417
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 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 GetBrightness()
Gets the current brightness level. In hardware mode, it is read from the MenuHandler.
Definition Menu.cpp:390
static uint8_t GetAccentBrightness()
Gets the current accent brightness level.
Definition Menu.cpp:399
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.
Implements an overflow distortion effect for pixel groups.
Definition Overflow.h:24
Applies rotational phase offsets to pixel groups.
Applies horizontal phase offsets to pixel groups.
Applies vertical phase offsets to pixel groups.
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
Applies a radial blur effect to pixel groups.
Definition RadialBlur.h:26
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.
Radially shifts the red, green, and blue channels of the pixels.
Definition ShiftR.h:26
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
An effect that applies a vertical blur to a pixel group.
@ 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.