ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
GalaxyAnimation.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 "../../Morph/Commissions/GalaxyFace.h"
8#include "../../Render/Scene.h"
9#include "../../Signals/FunctionGenerator.h"
10#include "../../Menu/SingleButtonMenu.h"
11#include "../../Sensors/APDS9960.h"
12
13#include "../../Materials/Animated/SpectrumAnalyzer.h"
14#include "../../Materials/Animated/AudioReactiveGradient.h"
15#include "../../Materials/Animated/Oscilloscope.h"
16#include "../../Materials/Animated/RainbowNoise.h"
17#include "../../Materials/Animated/RainbowSpiral.h"
18
19#include "../../Materials/MaterialAnimator.h"
20#include "../../Materials/MaterialMask.h"
21#include "../../Shapes/Ellipse.h"
22
23#include "../AnimationTracks/BlinkTrack.h"
24#include "../AnimationTracks/EyeMoveTrack.h"
25#include "../../Sensors/MicrophoneFourier_MAX9814.h"
26#include "../../Render/ObjectAlign.h"
27
28
29class GalaxyAnimation : public Animation<2> {
30private:
31 GalaxyFace pM;
32 Background background;
33 EasyEaseAnimator<20> eEA = EasyEaseAnimator<20>(EasyEaseInterpolation::Overshoot, 1.0f, 0.35f);
34
35 Ellipse blush = Ellipse(Vector2D(98.0f, 26.0f), Vector2D(60.0f, 45.0f), 0.0f);
36
37 //Materials
47
48 RGBColor gradientSpectrum[2] = {RGBColor(5, 162, 232), RGBColor(10, 170, 255)};
50
52
55
56 SpectrumAnalyzer sA = SpectrumAnalyzer(Vector2D(200, 100), Vector2D(100, 50), true, true);
59
60 //Animation controllers
63
71
73
74 ObjectAlign objA = ObjectAlign(Vector2D(0.0f, 0.0f), Vector2D(170.0f, 125.0f), Quaternion());
75
76 float offsetFace = 0.0f;
77 float offsetFaceSA = 0.0f;
78 float offsetFaceARG = 0.0f;
79 float offsetFaceOSC = 0.0f;
80 float eyeMoveParameter = 0.0f;
81 float eyeBack = 0.0f;
82 float eyePos = 0.0f;
83 uint8_t offsetFaceInd = 50;
84 uint8_t offsetFaceIndSA = 51;
85 uint8_t offsetFaceIndARG = 52;
86 uint8_t offsetFaceIndOSC = 53;
87 uint8_t eyeForwardInd = 54;
88 bool mirror = false;
89
91 eEA.AddParameter(pM.GetMorphWeightReference(GalaxyFace::OvO), GalaxyFace::OvO, 30, 0.0f, 1.0f);
92 eEA.AddParameter(pM.GetMorphWeightReference(GalaxyFace::EyeBack), GalaxyFace::EyeBack, 100, 0.0f, 1.0f);
93 eEA.AddParameter(&eyeBack, GalaxyFace::EyeBack2, 30, 0.0f, 1.0f);
94 eEA.AddParameter(pM.GetMorphWeightReference(GalaxyFace::HappyEye), GalaxyFace::HappyEye, 50, 0.0f, 1.0f);
95 eEA.AddParameter(pM.GetMorphWeightReference(GalaxyFace::HappyMouth), GalaxyFace::HappyMouth, 90, 0.0f, 1.0f);
96
97 eEA.AddParameter(pM.GetMorphWeightReference(GalaxyFace::Talk), GalaxyFace::Talk, 4, 0.0f, 1.0f);
98
99 eEA.AddParameter(pM.GetMorphWeightReference(GalaxyFace::HideBlush), GalaxyFace::HideBlush, 60, 1.0f, 0.0f);
100
101 eEA.AddParameter(&offsetFace, offsetFaceInd, 80, 0.0f, 1.0f);
102 eEA.AddParameter(&offsetFaceSA, offsetFaceIndSA, 80, 0.0f, 1.0f);
105 }
106
108 blink.AddParameter(pM.GetMorphWeightReference(GalaxyFace::Blink));
110 }
111
113 eEA.SetInterpolationMethod(GalaxyFace::HideBlush, EasyEaseInterpolation::Cosine);
114 eEA.SetInterpolationMethod(GalaxyFace::EyeBack, EasyEaseInterpolation::Cosine);
115 eEA.SetInterpolationMethod(GalaxyFace::EyeBack2, EasyEaseInterpolation::Cosine);
116
117 eEA.SetInterpolationMethod(GalaxyFace::Talk, EasyEaseInterpolation::Linear);
118
119 eEA.SetInterpolationMethod(eyeForwardInd, EasyEaseInterpolation::Cosine);
120 }
121
139
141 blink.Update();
142 eyeMove.Update();
143 }
144
145 void Default(){}
146
147 void Blush(){
148 eEA.AddParameterFrame(GalaxyFace::OvO, 1.0f);
149 eEA.AddParameterFrame(GalaxyFace::HideBlush, 0.0f);
150 }
151
152 void EyeBack(){
153 eEA.AddParameterFrame(GalaxyFace::EyeBack, 1.0f);
154 }
155
156 void EyeBack2(){
157 eEA.AddParameterFrame(GalaxyFace::EyeBack2, 1.0f);
158 }
159
160 void Happy(){
161 eEA.AddParameterFrame(GalaxyFace::HappyEye, 1.0f);
162 eEA.AddParameterFrame(GalaxyFace::HappyMouth, 1.0f);
163 }
164
166 eEA.AddParameterFrame(GalaxyFace::HappyEye, 1.0f);
167 eEA.AddParameterFrame(GalaxyFace::HappyMouth, 1.0f);
169 }
170
177
184
191
194 eEA.AddParameterFrame(GalaxyFace::Talk, MicrophoneFourierIT::GetCurrentMagnitude() / 2.0f);
195
196 if(MicrophoneFourierIT::GetCurrentMagnitude() > 0.05f){
197 //voiceDetection.Update(MicrophoneFourierIT::GetFourierFiltered(), MicrophoneFourierIT::GetSampleRate());
198
199 //eEA.AddParameterFrame(GalaxyFace::vrc_v_ee, voiceDetection.GetViseme(voiceDetection.EE));
200 //eEA.AddParameterFrame(GalaxyFace::vrc_v_ih, voiceDetection.GetViseme(voiceDetection.AH));
201 //eEA.AddParameterFrame(GalaxyFace::vrc_v_dd, voiceDetection.GetViseme(voiceDetection.UH));
202 //eEA.AddParameterFrame(GalaxyFace::vrc_v_rr, voiceDetection.GetViseme(voiceDetection.AR));
203 //eEA.AddParameterFrame(GalaxyFace::vrc_v_ch, voiceDetection.GetViseme(voiceDetection.ER));
204 //eEA.AddParameterFrame(GalaxyFace::vrc_v_aa, voiceDetection.GetViseme(voiceDetection.AH));
205 //eEA.AddParameterFrame(GalaxyFace::vrc_v_oh, voiceDetection.GetViseme(voiceDetection.OO));
206 }
207 }
208 }
209
211 switch(Menu::GetFaceColor()){
212 case 1: materialAnimator.AddMaterialFrame(redMaterial, 0.8f); break;
214 case 3: materialAnimator.AddMaterialFrame(whiteMaterial, 0.8f); break;
215 case 4: materialAnimator.AddMaterialFrame(greenMaterial, 0.8f); break;
216 case 5: materialAnimator.AddMaterialFrame(blueMaterial, 0.8f); break;
219 case 8: materialAnimator.AddMaterialFrame(rainbowSpiral, 0.8f); break;
220 case 9: materialAnimator.AddMaterialFrame(rainbowNoise, 0.8f); break;
221 default: break;
222 }
223 }
224
225public:
227 scene.AddObject(pM.GetObject());
228 scene.AddObject(background.GetObject());
229
230 LinkEasyEase();
232
234
236
237 pM.GetObject()->SetMaterial(&materialAnimator);
238 background.GetObject()->SetMaterial(&backgroundMaterial);
239
240 boop.Initialize(5);
241
242 MicrophoneFourierIT::Initialize(22, 8000, 30.0f, 100.0f);//8KHz sample rate, 50dB min, 120dB max
243 Menu::Initialize(4, 0, 500);//7 is number of faces
244
246 objA.SetMirrorX(true);
247 }
248
251 };
252
253 uint8_t GetBrightness(){
254 return Menu::GetBrightness();
255 };
256
257 void FadeIn(float stepRatio) override {}
258 void FadeOut(float stepRatio) override {}
259
261 return pM.GetObject();
262 }
263
265 this->mirror = mirror;
266 }
267
268 void Update(float ratio) override {
269
270 if(!mirror){
271 pM.Reset();
272
273 float xOffset = fGenMatXMove.Update();
274 float yOffset = fGenMatYMove.Update();
275
276 Menu::Update(ratio * 2.0f - floor(ratio));
277
279
280 bool isBooped = Menu::UseBoopSensor() ? boop.isBooped() : 0;
281 uint8_t mode = Menu::GetFaceState();//change by button press
282
283 MicrophoneFourierIT::Update();
284 sA.SetHueAngle(ratio * 360.0f * 4.0f);
287
288 aRG.SetRadius((xOffset + 2.0f) * 2.0f + 25.0f);
289 aRG.SetSize(Vector2D((xOffset + 2.0f) * 10.0f + 50.0f, (xOffset + 2.0f) * 10.0f + 50.0f));
290 aRG.SetHueAngle(ratio * 360.0f * 8.0f);
291 aRG.SetRotation(ratio * 360.0f * 2.0f);
292 aRG.SetPosition(Vector2D(80.0f + xOffset * 4.0f, 48.0f + yOffset * 4.0f));
293
294 oSC.SetSize(Vector2D(200.0f, 100.0f));
295 oSC.SetHueAngle(ratio * 360.0f * 8.0f);
296 oSC.SetPosition(Vector2D(100.0f, 50.0f));
297
299
300 if (isBooped){
301 Blush();
302 }
303 else{
304 if (mode == 0) Default();
305 else if (mode == 1) EyeBack2();
306 else if (mode == 2) Happy();
307 else HappyRainbow();
308 }
309
311
313
314 float leftEye = eyePos > 0.5f ? Mathematics::Map(eyePos, 0.5f, 1.0f, 0.0f, 1.0f) : 0.0f;
315
316 //left eye
317 pM.SetMorphWeight(GalaxyFace::EyeBack2, leftEye * eyeMoveParameter * eyeBack);
318
319 eEA.Update();
320 pM.Update();
321
322 blushMask.SetOpacity(eEA.GetValue(GalaxyFace::OvO));
323
324 float menuRatio = Menu::ShowMenu();
325
326 rainbowNoise.Update(ratio);
327 rainbowSpiral.Update(ratio);
330
331 pM.GetObject()->GetTransform()->SetRotation(Vector3D(0.0f, 0.0f, -7.5f));
332
333 uint8_t faceSize = Menu::GetFaceSize();
334
335 float scale = menuRatio * 0.5f + 0.5f;
336 float faceSizeOffset = faceSize * 8.0f;
337
338 objA.SetEdgeMargin(2.0f);
339 objA.SetCameraMax(Vector2D(110.0f + faceSizeOffset, 125.0f).Multiply(scale));
340
341 objA.AlignObjects(scene.GetObjects(), 1);
342
343 pM.GetObject()->GetTransform()->SetPosition(Vector3D(xOffset + 5.0f, yOffset - 150.0f * offsetFace + 5.0f, 0.0f));
344 pM.GetObject()->UpdateTransform();
345 }
346 else {
347 pM.Reset();
348
350
351 float xOffset = fGenMatXMove.Update();
352 float yOffset = fGenMatYMove.Update();
353
354 float rightEye = eyePos <= 0.5f ? Mathematics::Map(eyePos, 0.5f, 0.0f, 0.0f, 1.0f) : 0.0f;
355
356 //right eye
357 pM.SetMorphWeight(GalaxyFace::EyeBack2, rightEye * eyeMoveParameter * eyeBack);
358
360 pM.Update();
361
362 pM.GetObject()->GetTransform()->SetRotation(Vector3D(0.0f, 0.0f, -7.5f));
363
364 uint8_t faceSize = Menu::GetFaceSize();
365
366 float menuRatio = Menu::ShowMenu();
367 float scale = menuRatio * 0.5f + 0.5f;
368 float faceSizeOffset = faceSize * 8.0f;
369
370 objA.SetEdgeMargin(2.0f);
371 objA.SetCameraMax(Vector2D(110.0f + faceSizeOffset, 125.0f).Multiply(scale));
372
373 objA.AlignObjects(scene.GetObjects(), 1);
374
375 pM.GetObject()->GetTransform()->SetPosition(Vector3D(xOffset + 5.0f, yOffset - 150.0f * offsetFace + 5.0f, 0.0f));
376 pM.GetObject()->UpdateTransform();
377 }
378 }
379};
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 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.
float GetValue(uint16_t dictionaryValue) override
Gets the current value of a parameter.
void SetParameters() override
Applies the current animation values to the parameters.
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.
Represents an ellipse in 2D space.
Definition Ellipse.h:21
A template class for animating eye movements using keyframes.
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.
FunctionGenerator fGenMatHue
SimpleMaterial greenMaterial
FunctionGenerator fGenMatYMove
SpectrumAnalyzer sA
EyeMoveTrack< 1 > eyeMove
Oscilloscope oSC
EasyEaseAnimator< 20 > eEA
SimpleMaterial redMaterial
RainbowSpiral rainbowSpiral
SimpleMaterial blueMaterial
MaterialMask blushMask
void AudioReactiveGradientFace()
SimpleMaterial yellowMaterial
BlinkTrack< 1 > blink
void ChangeInterpolationMethods()
GradientMaterial< 2 > gradientMat
FunctionGenerator fGenMatPos
FunctionGenerator fGenScale
Background background
FunctionGenerator fGenRotation
SimpleMaterial orangeMaterial
void SetCameraMirror(bool mirror)
void FadeIn(float stepRatio) override
void FadeOut(float stepRatio) override
RainbowNoise rainbowNoise
FunctionGenerator fGenMatXMove
MaterialAnimator< 10 > materialAnimator
SimpleMaterial purpleMaterial
void Update(float ratio) override
RGBColor gradientSpectrum[2]
MaterialAnimator< 4 > backgroundMaterial
uint8_t GetBrightness()
uint8_t GetAccentBrightness()
Object3D * GetObject()
SimpleMaterial whiteMaterial
AudioReactiveGradient aRG
FunctionGenerator fGenEyeLook1
Creates a customizable gradient material for rendering.
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.
Combines two materials using a shape as a mask.
void SetOpacity(float opacity)
Sets the opacity of the mask effect.
@ Lighten
Chooses the lighter color.
Definition Material.h:40
@ Add
Adds colors together.
Definition Material.h:35
@ Replace
Replaces the base color.
Definition Material.h:44
static T Map(T value, T inLow, T inMax, T outMin, T outMax)
Maps a value from one range to another.
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 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 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 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
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 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