mirror of
https://github.com/eliasstepanik/FluidSimulation.git
synced 2026-01-11 13:38:28 +00:00
Cleanup
This commit is contained in:
parent
0b7fa3e99f
commit
c34a7c4e40
1
.idea/.idea.PixelEngine/.idea/.name
generated
Normal file
1
.idea/.idea.PixelEngine/.idea/.name
generated
Normal file
@ -0,0 +1 @@
|
||||
PixelEngine
|
||||
8
.idea/.idea.PixelEngine/.idea/indexLayout.xml
generated
Normal file
8
.idea/.idea.PixelEngine/.idea/indexLayout.xml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="UserContentModel">
|
||||
<attachedFolders />
|
||||
<explicitIncludes />
|
||||
<explicitExcludes />
|
||||
</component>
|
||||
</project>
|
||||
6
.idea/.idea.PixelEngine/.idea/projectSettingsUpdater.xml
generated
Normal file
6
.idea/.idea.PixelEngine/.idea/projectSettingsUpdater.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RiderProjectSettingsUpdater">
|
||||
<option name="vcsConfiguration" value="2" />
|
||||
</component>
|
||||
</project>
|
||||
6
.idea/.idea.PixelEngine/.idea/vcs.xml
generated
Normal file
6
.idea/.idea.PixelEngine/.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@ -1,20 +0,0 @@
|
||||
using System.Numerics;
|
||||
|
||||
namespace PixelEngine;
|
||||
|
||||
public class BlackHole : Hole
|
||||
{
|
||||
public BlackHole(Vector2 position, int radius, float mass) : base(position, mass)
|
||||
{
|
||||
this.radius = radius;
|
||||
}
|
||||
|
||||
public override void Spawn(Fluid fluid)
|
||||
{
|
||||
fluid.reduceDensity((int)position.X, (int)position.Y, mass, radius);
|
||||
}
|
||||
|
||||
public override Vector2 position { get; set; }
|
||||
public int radius { get; set; }
|
||||
public override float mass { get; set; }
|
||||
}
|
||||
@ -1,4 +1,5 @@
|
||||
using Raylib_CsLo;
|
||||
using System.Numerics;
|
||||
using Raylib_CsLo;
|
||||
using static Raylib_CsLo.RayMath;
|
||||
|
||||
namespace PixelEngine;
|
||||
@ -130,16 +131,9 @@ public class Fluid
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*var amtX = Raylib.GetMouseX();
|
||||
var amtY = Raylib.GetMouseY();
|
||||
|
||||
addVelocity(amtX / scale, amtY / scale, amtX * 2, amtY * 2);*/
|
||||
}
|
||||
|
||||
|
||||
public void addVelocity(int x, int y, float amountX, float amountY) {
|
||||
int index = IX(x, y);
|
||||
this.Vx[index] += amountX;
|
||||
|
||||
91
PixelEngine/Game.cs
Normal file
91
PixelEngine/Game.cs
Normal file
@ -0,0 +1,91 @@
|
||||
using System.Numerics;
|
||||
using static Raylib_CsLo.Raylib;
|
||||
using static Raylib_CsLo.RayGui;
|
||||
using Raylib_CsLo;
|
||||
|
||||
namespace PixelEngine;
|
||||
|
||||
public class Game
|
||||
{
|
||||
private const int Size = 64;
|
||||
private const int Scale = 10;
|
||||
private const int Iter = 10;
|
||||
private const float Dt = 0.2f;
|
||||
private const float Diffusion = 0f;
|
||||
private const float Viscosity = 0.0000001f;
|
||||
|
||||
private const string WindowTitle = "Fluid Simulation";
|
||||
private const int TargetFps = 60;
|
||||
|
||||
private Fluid _fluid = null!;
|
||||
|
||||
public Vector2 PMouse;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
_fluid = new Fluid(Dt, Diffusion, Viscosity, Size, Iter, Scale);
|
||||
|
||||
InitWindow(Size * Scale, Size * Scale, WindowTitle);
|
||||
SetTargetFPS(TargetFps);
|
||||
}
|
||||
|
||||
public void HandleInput()
|
||||
{
|
||||
|
||||
|
||||
// Add Density
|
||||
if (IsMouseButtonDown(MouseButton.MOUSE_BUTTON_LEFT))
|
||||
{
|
||||
_fluid.addDensity(GetMouseX() / Scale, GetMouseY() / Scale, 100);
|
||||
}
|
||||
|
||||
|
||||
// Reduce Density
|
||||
else if (IsMouseButtonDown(MouseButton.MOUSE_BUTTON_RIGHT))
|
||||
{
|
||||
_fluid.reduceDensity(GetMouseX() / Scale, GetMouseY() / Scale, 100,5);
|
||||
|
||||
|
||||
//TODO: Suction for Density Reduction
|
||||
|
||||
}
|
||||
|
||||
//Mouse Velocity
|
||||
if (Math.Abs(GetMouseX() - PMouse.X) > 0.1 || Math.Abs(GetMouseY() - PMouse.Y) > 0.1)
|
||||
{
|
||||
var amtX = GetMouseX() - PMouse.X;
|
||||
var amtY = GetMouseY() - PMouse.Y;
|
||||
|
||||
_fluid.addVelocity(GetMouseX() / Scale, GetMouseY() / Scale, amtX, amtY);
|
||||
|
||||
PMouse = GetMousePosition();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void UpdateSim()
|
||||
{
|
||||
_fluid.step();
|
||||
}
|
||||
|
||||
public void UpdateDraw()
|
||||
{
|
||||
BeginDrawing();
|
||||
ClearBackground(BLACK);
|
||||
|
||||
//Debug
|
||||
DrawText("FPS: " + GetFPS(), 10, 10, 10, WHITE);
|
||||
|
||||
|
||||
//Create a GUI Slider for Viscosity
|
||||
var rect = new Rectangle(10, 20, 100, 20);
|
||||
GuiSlider(rect, "", "", _fluid.visc, 0.0000001f, 0.01f);
|
||||
|
||||
_fluid.renderD();
|
||||
|
||||
EndDrawing();
|
||||
}
|
||||
}
|
||||
@ -1,15 +0,0 @@
|
||||
using System.Numerics;
|
||||
|
||||
namespace PixelEngine;
|
||||
|
||||
public abstract class Hole
|
||||
{
|
||||
public Hole(Vector2 position, float mass)
|
||||
{
|
||||
this.position = position;
|
||||
this.mass = mass;
|
||||
}
|
||||
public abstract void Spawn(Fluid fluid);
|
||||
public abstract Vector2 position { get; set; }
|
||||
public abstract float mass { get; set; }
|
||||
}
|
||||
@ -1,4 +1,5 @@
|
||||
using System.Drawing;
|
||||
using System.Diagnostics.SymbolStore;
|
||||
using System.Drawing;
|
||||
using System.Numerics;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using static Raylib_CsLo.Raylib;
|
||||
@ -8,125 +9,15 @@ using System.Drawing;
|
||||
using PixelEngine;
|
||||
using Raylib_CsLo;
|
||||
|
||||
Game game = new Game();
|
||||
|
||||
/*var c = new CircleAndClock();
|
||||
c.Run();*/
|
||||
var N = 64;
|
||||
var Scale = 10;
|
||||
var Iter = 10;
|
||||
float t = 0;
|
||||
int whiteholes = 4;
|
||||
int blackholes = 1;
|
||||
|
||||
Fluid fluid;
|
||||
|
||||
fluid = new Fluid(0.2f, 0, 0.0000001f, N, Iter, Scale);
|
||||
InitWindow(N * Scale, N * Scale, "Raylib_CsLo");
|
||||
SetTargetFPS(60);
|
||||
Random rd = new Random();
|
||||
|
||||
var pMouseX = GetMouseX();
|
||||
var pMouseY = GetMouseY();
|
||||
|
||||
var whiteholesA = new WhiteHole[whiteholes];
|
||||
var blackholesA = new BlackHole[blackholes];
|
||||
|
||||
for (int i = 0; i < whiteholes; i++)
|
||||
{
|
||||
whiteholesA[i] = new WhiteHole(
|
||||
new Vector2(rd.Next(3, N - 3), rd.Next(3, N - 3)),
|
||||
new Vector2(rd.Next(50, 100), rd.Next(50, 100)),
|
||||
rd.Next(0, 100),
|
||||
rd.Next(0, 100)
|
||||
);
|
||||
}
|
||||
|
||||
for (int i = 0; i < blackholes; i++)
|
||||
{
|
||||
blackholesA[i] = new BlackHole(
|
||||
new Vector2(rd.Next(3, N - 3), rd.Next(3, N - 3)),
|
||||
rd.Next(0, 3),
|
||||
rd.Next(0,200)
|
||||
);
|
||||
}
|
||||
|
||||
game.PMouse = GetMousePosition();
|
||||
game.Start();
|
||||
|
||||
|
||||
while (!WindowShouldClose())
|
||||
{
|
||||
BeginDrawing();
|
||||
ClearBackground(BLACK);
|
||||
DrawFPS(10,10);
|
||||
|
||||
/*int cx = (int)0.5*N/Scale;
|
||||
int cy = (int)0.5*N/Scale;
|
||||
for (int i = -1; i <= 1; i++) {
|
||||
for (int j = -1; j <= 1; j++) {
|
||||
fluid.addDensity(cx+i, cy+j, rd.Next(50, 150));
|
||||
}
|
||||
}*/
|
||||
/*for (int i = 0; i < 2; i++) {
|
||||
float angle = noise(t) * TWO_PI * 2;
|
||||
PVector v = PVector.fromAngle(angle);
|
||||
v.mult(0.2);
|
||||
t += 0.01;
|
||||
fluid.addVelocity(cx, cy, v.x, v.y );
|
||||
}*/
|
||||
|
||||
|
||||
/*fluid.step();
|
||||
fluid.renderD();*/
|
||||
|
||||
|
||||
if (IsMouseButtonDown(MouseButton.MOUSE_BUTTON_LEFT))
|
||||
fluid.addDensity((int)GetMouseX() / Scale, (int)GetMouseY() / Scale, 100);
|
||||
else if (IsMouseButtonDown(MouseButton.MOUSE_BUTTON_RIGHT))
|
||||
{
|
||||
fluid.reduceDensity((int)GetMouseX() / Scale, (int)GetMouseY() / Scale, 100, 5);
|
||||
|
||||
|
||||
//TODO: Suction for Density Reduction
|
||||
/*var amtX = GetMouseX() - pMouseX;
|
||||
var amtY = GetMouseY() - pMouseY;
|
||||
|
||||
fluid.addVelocity((int)GetMouseX() / Scale, (int)GetMouseY() / Scale, amtX, amtY);*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
foreach (var hole in blackholesA)
|
||||
{
|
||||
hole.Spawn(fluid);
|
||||
}
|
||||
|
||||
foreach (var hole in whiteholesA)
|
||||
{
|
||||
hole.Spawn(fluid);
|
||||
}
|
||||
|
||||
|
||||
/*fluid.addDensity(N - 3 , 3, 100);
|
||||
fluid.addVelocity(N - 3 , 3, -10f, 0);*/
|
||||
|
||||
|
||||
|
||||
|
||||
/*if (GetMouseX() != pMouseX || GetMouseY() != pMouseY)
|
||||
{
|
||||
|
||||
var amtX = GetMouseX() - pMouseX;
|
||||
var amtY = GetMouseY() - pMouseY;
|
||||
|
||||
fluid.addVelocity((int)GetMouseX() / Scale, (int)GetMouseY() / Scale, amtX, amtY);
|
||||
}*/
|
||||
|
||||
pMouseX = GetMouseX();
|
||||
pMouseY = GetMouseY();
|
||||
|
||||
fluid.step();
|
||||
fluid.renderD();
|
||||
|
||||
|
||||
EndDrawing();
|
||||
game.HandleInput();
|
||||
game.UpdateSim();
|
||||
game.UpdateDraw();
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
using System.Numerics;
|
||||
|
||||
namespace PixelEngine;
|
||||
|
||||
public class WhiteHole : Hole
|
||||
{
|
||||
public override void Spawn(Fluid fluid)
|
||||
{
|
||||
fluid.addDensity((int) position.X, (int) position.Y, mass);
|
||||
fluid.addVelocity((int) position.X, (int) position.Y, direction.X * speed, direction.Y * speed);
|
||||
}
|
||||
|
||||
public override Vector2 position { get; set; }
|
||||
public Vector2 direction { get; set; }
|
||||
public override float mass { get; set; }
|
||||
public float speed { get; set; }
|
||||
|
||||
public WhiteHole(Vector2 position, Vector2 direction, float mass, float speed) : base(position, mass)
|
||||
{
|
||||
this.direction = direction;
|
||||
this.speed = speed;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user