added velocity evolution

This commit is contained in:
Lauchmelder 2021-12-10 22:18:20 +01:00
parent aa8393ee4c
commit f8e8cc64b4
5 changed files with 174 additions and 30 deletions

View file

@ -24,22 +24,7 @@ VectorField::VectorField(int width, int height, const std::vector<double>& hori,
horizontal = hori;
vertical = vert;
for (int y = 0; y < this->height; y++)
{
for (int x = 0; x < this->width; x++)
{
double u = horizontal[y * this->width + x];
double v = vertical[y * this->width + x];
double magnitude = u + v;
biggestMagnitude += (biggestMagnitude < magnitude) * (magnitude - biggestMagnitude);
}
}
if (biggestMagnitude == 0.0) // should use an epsilon probably
biggestMagnitude = 1.0;
biggestMagnitude = sqrt(biggestMagnitude * 5.0);
RecalculateMagnitude();
}
void VectorField::Draw(SDL_Renderer* renderer, const SDL_Rect& targetRect)
@ -68,3 +53,23 @@ void VectorField::Draw(SDL_Renderer* renderer, const SDL_Rect& targetRect)
}
}
}
void VectorField::RecalculateMagnitude()
{
for (int y = 0; y < this->height; y++)
{
for (int x = 0; x < this->width; x++)
{
double u = horizontal[y * this->width + x];
double v = vertical[y * this->width + x];
double magnitude = u + v;
biggestMagnitude += (biggestMagnitude < magnitude) * (magnitude - biggestMagnitude);
}
}
if (biggestMagnitude == 0.0) // should use an epsilon probably
biggestMagnitude = 1.0;
biggestMagnitude = sqrt(biggestMagnitude * 5.0);
}