ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
VectorFieldAnimation.h
Go to the documentation of this file.
1#pragma once
2
3#include "Animation.h"
4#include "../Objects/SolidCube.h"
5#include "../Math/FunctionGenerator.h"
6#include "../Morph/ProtoDRMorph.h"
7
8#include "../Materials/VectorField2D.h"
9
10class VectorFieldAnimation : public Animation{
11private:
12 ProtoDR pM;
13
14 SolidCube cube;
20
21 RGBColor spectrum1[6] = {RGBColor(255, 255, 0), RGBColor(0, 0, 0), RGBColor(0, 255, 255), RGBColor(0, 0, 0), RGBColor(255, 0, 255), RGBColor(0, 0, 0)};
22 RGBColor spectrum2[6] = {RGBColor(255, 0, 0), RGBColor(0, 0, 0), RGBColor(0, 255, 0), RGBColor(0, 0, 0), RGBColor(0, 0, 255), RGBColor(0, 0, 0)};
23 RGBColor spectrum3[7] = {RGBColor(255, 0, 0), RGBColor(255, 255, 0), RGBColor(0, 255, 0), RGBColor(0, 255, 255), RGBColor(0, 0, 255), RGBColor(255, 0, 255), RGBColor(255, 0, 0)};
26
27public:
28 VectorFieldAnimation() : Animation(1) {
29 scene->AddObject(cube.GetObject());
30
31 cube.GetObject()->SetMaterial(&vectorField);
32 }
33
34 void FadeIn(float stepRatio) override {}
35 void FadeOut(float stepRatio) override {}
36
37 void Update(float ratio) override {
38 float shift = fGenMatPos.Update();
39 //float size = fGenMatSize.Update();
40 //float rotate = fGenMatRot.Update();
41 float period = fGenMatPeriod.Update();
42 float amplitude = fGenMatAmpl.Update();
43
44 float x = sinf(ratio * 3.14159f / 180.0f * 360.0f * 4.0f) * 50.0f + sinf(ratio * 3.14159f / 180.0f * 360.0f * 3.0f) * 50.0f;
45 float y = cosf(ratio * 3.14159f / 180.0f * 360.0f * 6.0f) * 10.0f;
46
47 pM.SetMorphWeight(ProtoDR::HideBlush, 1.0f);
48 pM.SetMorphWeight(ProtoDR::HideSecondEye, 1.0f);
49 pM.Update();
50
51 pM.GetObject()->GetTransform()->SetRotation(Vector3D(0, 180.0f, 0.0f));
52 pM.GetObject()->GetTransform()->SetPosition(Vector3D(x, y - 250.0f, 600.0f));
53 pM.GetObject()->GetTransform()->SetScale(Vector3D(2.0f, 2.0f, 2.0f));
54
55 pM.GetObject()->UpdateTransform();
56
58 vectorField.SetSize(550, 450);
60 //vectorField.SetRotation(ratio * 360.0f);
61
62 //if (ratio < 0.02f) vectorField.SineField(ratio, period, amplitude);
63 //if (ratio < 0.2f) vectorField.StepField(ratio, 40.0f, 5);
64 vectorField.ObjectField(pM.GetObject(), 20.0f);
65 //vectorField.MovingSquareField(ratio, 160.0f, 15);
66 vectorField.Diffuse(0.05f, 0.0001f);
67 vectorField.Advect(0.00001f);
68 //vectorField.ObjectField(pM.GetObject());
69
70 cube.GetObject()->ResetVertices();
71 cube.GetObject()->GetTransform()->SetScale(Vector3D(1000, 1000, 1));
72 cube.GetObject()->UpdateTransform();
73 }
74};
A class to generate various waveform functions with customizable parameters.
@ Sine
Sine waveform.
float Update()
Updates and calculates the next value of the waveform.
Creates a customizable gradient material for rendering.
Represents an RGB color and provides methods for manipulation.
Definition RGBColor.h:23
Represents a 3D vector (X, Y, Z) and provides methods for vector arithmetic.
Definition Vector3D.h:26
A class for managing and rendering 2D vector fields.
void RenderDensity()
Renders the density values of the vector field.
void Advect(float dt)
Advances the vector field using advection.
void SetPosition(float posX, float posY)
Sets the position of the vector field.
void ObjectField(Object3D *object, float intensity)
Generates a field effect based on a 3D object's position and shape.
void Diffuse(float viscosity, float dt)
Performs diffusion on the vector field.
void SetSize(float sizeX, float sizeY)
Sets the size of the vector field.
FunctionGenerator fGenMatAmpl
GradientMaterial colorDirection
FunctionGenerator fGenMatPeriod
FunctionGenerator fGenMatPos
void FadeIn(float stepRatio) override
void FadeOut(float stepRatio) override
void Update(float ratio) override
FunctionGenerator fGenMatRot
FunctionGenerator fGenMatSize