Euler fluid simulated with CPP and SFML

Related tags

Game euler-fluid-cpp
Overview

Euler fluid simulation

Demo Gif

Inspiration

This project is based upon an article by Mike Ash.

For more info see: https://mikeash.com/pyblog/fluid-simulation-for-dummies.html

What is it?

This Project is a visualisation of the famous Navier Stokes Equations.

Simplified this project is a grid based simulation that emulates and visualizes how fluids act, as well as how their behaviour changes if you change the viscosity or diffusion of a certain liquid.

If you have any improvements or ideas, please let me know.

Also feel free to report any bugs that may occur.

How to use

Pressing left mouse will add density.

Dragging the mouse will apply force towards the moving direction.

Building the project

To build the project simply execute make build in the directory of the makefile.

Make sure to also install the library SFML which is needed to build the project.

To install SFML under Linux: sudo apt-get install libsfml-dev

You might also like...
A multi core friendly rigid body physics and collision detection library suitable for games and VR applications.
A multi core friendly rigid body physics and collision detection library suitable for games and VR applications.

Jolt Physics Library A multi core friendly rigid body physics and collision detection library suitable for games and VR applications. A YouTube video

Source and data to build Sonic 3 A.I.R. (Angel Island Revisited) and the Oxygen Engine

Sonic 3 A.I.R. Source code incl. dependencies for "Sonic 3 - Angel Island Revisited", a fan-made remaster of Sonic 3 & Knuckles. Project homepage: htt

Freelancer: HD Edition is a mod that aims to improve every visual, aural, and gameplay aspect of the game Freelancer (2003) while keeping the look and feel as close to vanilla as possible.

Freelancer: HD Edition Freelancer: HD Edition is a mod that aims to improve every visual, aural, and gameplay aspect of the game Freelancer (2003) whi

The Atomic Game Engine is a multi-platform 2D and 3D engine with a consistent API in C++, C#, JavaScript, and TypeScript
The Atomic Game Engine is a multi-platform 2D and 3D engine with a consistent API in C++, C#, JavaScript, and TypeScript

The Atomic Game Engine is a multi-platform 2D and 3D engine with a consistent API in C++, C#, JavaScript, and TypeScript

GB Studio is a quick and easy to use retro adventure game creator for Game Boy available for Mac, Linux and Windows
GB Studio is a quick and easy to use retro adventure game creator for Game Boy available for Mac, Linux and Windows

GB Studio is a quick and easy to use retro adventure game creator for Game Boy available for Mac, Linux and Windows

Gaming meets modern C++ - a fast and reliable entity-component system (ECS) and much more
Gaming meets modern C++ - a fast and reliable entity-component system (ECS) and much more

EnTT is a header-only, tiny and easy to use entity-component system (and much more) written in modern C++. Among others, it's also used in Minecraft by Mojang and The Forge by Confetti.

Distributed server for social and realtime games and apps.
Distributed server for social and realtime games and apps.

Distributed server for social and realtime games and apps. Features Users - Register/login new users via social networks, email, or device ID. Storage

Godot Engine – Multi-platform 2D and 3D game engine
Godot Engine – Multi-platform 2D and 3D game engine

Godot Engine 2D and 3D cross-platform game engine Godot Engine is a feature-packed, cross-platform game engine to create 2D and 3D games from a unifie

The official distribution of olcPixelGameEngine, a tool used in javidx9's YouTube videos and projects

olcPixelGameEngine The official distribution of olcPixelGameEngine, a tool used in javidx9's YouTube videos and projects. You only need the one file -

Comments
  • Refactor the pointers in the container header file to arrays

    Refactor the pointers in the container header file to arrays

    class Container {
    private:
    	Physics physics;
    
    	int size;
    
    	float dt;
    	float diff;
    	float visc;
    	
    	float* px;
    	float* py;
    
    	float* x;
    	float* y;
    
    	float* previousDensity;
    	float* density;
    
    	void InitArr(float* arr, int size);
    public:
    	Container();
    	Container(float dt, float diff, float visc);
    	~Container();
    
    	void AddDensity(float x, float y, float amount);
    	void AddVelocity(float x, float y, float px, float py);
    	void Step();
    	void Render(sf::RenderWindow& win);
    	void FadeDensity(int size);
    };
    

    to

    extern const int SIZE;
    extern const int SCALE;
    class Container {
    private:
    	Physics physics;
    
    	int size;
    
    	float dt;
    	float diff;
    	float visc;
    	
    	float px[SIZE*SIZE];
    	float py[SIZE*SIZE];
    
    	float x[SIZE*SIZE];
    	float y[SIZE*SIZE];
    
    	float previousDensity[SIZE*SIZE];
    	float density[SIZE*SIZE];
    
    	void InitArr(float* arr, int size);
    public:
    	Container();
    	Container(float dt, float diff, float visc);
    	~Container();
    
    	void AddDensity(float x, float y, float amount);
    	void AddVelocity(float x, float y, float px, float py);
    	void Step();
    	void Render(sf::RenderWindow& win);
    	void FadeDensity(int size);
    };
    
    opened by vickoza 2
  • Sim.cpp Compiler Error C2280

    Sim.cpp Compiler Error C2280

    Seem to be getting an odd error on line 6 of Sim.cpp

    Sim::Sim() : options(Options()), container(Container(0.2f, 0, 0.0000001f)), win(sf::RenderWindow(sf::VideoMode(SIZE* SCALE, SIZE* SCALE), "Euler fluid simulation - Github: https://github.com/driema/euler-fluid-cpp", sf::Style::Titlebar | sf::Style::Close)) {}

    Severity Code Description Project File Line Suppression State Error C2280 'sf::RenderWindow::RenderWindow(const sf::RenderWindow &)': attempting to reference a deleted function Euler C:\VSProjects\Euler\sim.cpp 6

    Any solutions?

    opened by lawrencematthew19942016 1
  • About Fluids and rigid bodies

    About Fluids and rigid bodies

    Hello.

    First; I want to congratulate you for your contribution. It is great!!

    Second; I am considering a project where I want to simulate volcanic lava running down the slope of a mountain (in 2D).

    I don't know if it is possible to do it with this approach. The first question I have is whether it is possible to simulate the effect of the lava going around obstacles it may encounter on its way, such as houses (rectangles). Do you have an opinion on how to implement this?

    In other words, I wonder how this "fluid" will work interacting with rigid objects/bodies. I guess, as it is not a particle system per se there are no collisions to detect. :-D

    Thanks!

    DJuego

    opened by DJuego 0
Releases(v1.0)
  • v1.0(Mar 8, 2021)

    Basic Euler fluid simulation.

    • Mouse input, to control force and density
    • Keyboard input, to switch between color modes (default, hsb, velocity)

    Before executing the binary make sure that you have SFML installed to your standard library path. For more information on how to install SFML on Linux, please take a look at the Readme or visit the SFML Homepage.

    Windows executable is not included yet, but will most likely be added in the near future.

    Info: If you can't execute the binary because of a Permission denied please make sure to give yourself the necessary rights via chmod 755 ./simulation.

    Source code(tar.gz)
    Source code(zip)
    simulation(34.96 KB)
Owner
null
Mineswepper game created using SFML

SFML Mineswepper About Simple mineswepper game with fixed map size (this can be changed by changing map size by and compiling the project by yourself)

Piotr Warmke 1 Nov 8, 2021
Care race game built in c++ with sfml. this project is done in 3rd semester of csit for demonstration of computer graphics.

Car Race Car race is simple game which has been built by using SFML in c++ implementing concepts of Computer Graphics for project Work of 3rd semester

subash kc 4 Dec 18, 2021
Simple Ball-Based Game, made using SFML.

Ball Ball is a basic windows-only, ball-based game, made using C++ SFML. The goal of the game is to claim 5 balls every 10 seconds. Ball can never be

orlando 2 Dec 20, 2021
Xelu's Controllers & Keyboard Prompts as an Unreal Plugin for programmatic use (cpp / bp)

ue-xelu-icons Xelu's FREE Controllers & Keyboard Prompts as an Unreal Plugin for programmatic use (cpp / bp) This plugin exposes a Blueprint Library w

Mickael Daniel 9 Dec 3, 2022
A Binary Clock. Written 3 different ways. C and SDL, Python and PyGame, Python and PyGame Zero.

Super Clock A Binary Clock. Written 3 different ways. Python with PyGame Zero, Python with PyGame and C with SDL2. Time is displayed in 3 groups of 8

null 3 Dec 8, 2021
Gaming meets modern C++ - a fast and reliable entity component system (ECS) and much more

EnTT is a header-only, tiny and easy to use library for game programming and much more written in modern C++. Among others, it's used in Minecraft by

Michele Caini 7.6k Jan 4, 2023
Powerful, mature open-source cross-platform game engine for Python and C++, developed by Disney and CMU

Panda3D Panda3D is a game engine, a framework for 3D rendering and game development for Python and C++ programs. Panda3D is open-source and free for a

Panda3D 3.6k Dec 31, 2022
OGRE is a scene-oriented, flexible 3D engine written in C++ designed to make it easier and more intuitive for developers to produce games and demos utilising 3D hardware.

OGRE (Object-Oriented Graphics Rendering Engine) is a scene-oriented, flexible 3D engine written in C++ designed to make it easier and more intuitive for developers to produce games and demos utilising 3D hardware. The class library abstracts all the details of using the underlying system libraries like Direct3D and OpenGL and provides an interface based on world objects and other intuitive classes.

null 3.1k Jan 3, 2023
Minecraft 4k: decompiled, translated to C using SDL for graphics and input, and improved upon

M4KC Minecraft 4K - C Rewrite For those who don't know, Minecraft 4K was a stripped down version of Minecraft submitted by Notch to the Java 4K Game P

Sasha Koshka 38 Oct 9, 2022
an AI and gameplay editor for game development, written by c++ , suppport lua and python

an AI and gameplay editor for game development, written by c++ , suppport lua and python

null 26 Dec 14, 2022