#include #include #include #include #include #include #include #include #include #include #include "../util/grid/grid3eigen.hpp" #include "../util/output/bmpwriter.hpp" #include "../util/output/frame.hpp" #include "../util/timing_decorator.cpp" #include "../util/noise/pnoise2.hpp" #include "../util/noise/pnoise.cpp" #include "../util/output/aviwriter.hpp" #include "../imgui/imgui.h" #include "../imgui/backends/imgui_impl_glfw.h" #include "../imgui/backends/imgui_impl_opengl3.h" #include #include "../stb/stb_image.h" struct fluidParticle { Eigen::Matrix pos; Eigen::Matrix velocity; Eigen::Matrix acceleration; Eigen::Matrix forceAccumulator; float pressure; float viscosity; float restitution; float mass; }; struct gridDefaults { float gridSizeCube = 1024; }; Eigen::Matrix posGen() { static std::random_device rd; static std::mt19937 gen(rd()); static std::normal_distribution dist(0.0f, 1024.0f); return Eigen::Matrix( dist(gen), dist(gen), dist(gen) ); } class fluidSim { std::unordered_map> idposMap; Octree grid; void spawnParticles(fluidParticle toSpawn, int count) { for (int i = 0; i < count; i++) { Eigen::Matrix pos = posGen(); grid.set(toSpawn, pos, true, {toSpawn.mass / 1000, toSpawn.mass / 1000, toSpawn.mass / 1000}, 1, true, 1, false); } } void applyPhysics() { for (auto& meh : idposMap) { std::shared_ptr::NodeData> mehdata = grid.find(meh.second); std::vector::NodeData>> neighbors = grid.findInRadius(meh.second, mehdata->data.mass); ///TODO: // apply velocity to have particle move // use mass of neighboring particles to change direction towards them // ressure pushes particles away if they are too close // resitution controls how much pressure builds up based on how close particles are // have to find a way to have a clump use their combined mass instead of individual mass. //if a particle leaves the grid, destroy it and spawn a new one for (auto& neighbor : neighbors) { } } } };