From e99bbc08afbd20364d6944202a7615c69981034a Mon Sep 17 00:00:00 2001 From: Yggdrasil75 Date: Mon, 23 Feb 2026 15:00:58 -0500 Subject: [PATCH] pushing home --- makefile | 2 +- util/sim/planet.hpp | 111 ++++++++++++++++++++++++++++++++++---------- 2 files changed, 88 insertions(+), 25 deletions(-) diff --git a/makefile b/makefile index 60b4625..55510ef 100644 --- a/makefile +++ b/makefile @@ -34,7 +34,7 @@ endif CXXFLAGS = $(BASE_CXXFLAGS) $(SIMD_CXXFLAGS) # Source files -SRC := $(SRC_DIR)/g3etest.cpp +SRC := $(SRC_DIR)/ptest.cpp #SRC := $(SRC_DIR)/g2chromatic2.cpp SRC += $(IMGUI_DIR)/imgui.cpp $(IMGUI_DIR)/imgui_demo.cpp $(IMGUI_DIR)/imgui_draw.cpp $(IMGUI_DIR)/imgui_tables.cpp $(IMGUI_DIR)/imgui_widgets.cpp SRC += $(IMGUI_DIR)/backends/imgui_impl_glfw.cpp $(IMGUI_DIR)/backends/imgui_impl_opengl3.cpp diff --git a/util/sim/planet.hpp b/util/sim/planet.hpp index c29e84e..6d1808e 100644 --- a/util/sim/planet.hpp +++ b/util/sim/planet.hpp @@ -13,6 +13,7 @@ #include #include #include +#include #include "../grid/grid3eigen.hpp" #include "../timing_decorator.cpp" @@ -58,6 +59,7 @@ struct Particle { float soundSpeed = 100.0f; std::unordered_map neighbors; + std::map nearNeighbors; }; struct planetConfig { @@ -94,16 +96,17 @@ struct planetConfig { }; struct PlateConfig { - int plateId; + int plateId = -1; Eigen::Vector3f plateEulerPole; Eigen::Vector3f direction; - float angularVelocity; - float thickness; - float density; - float rigidity; - float temperature; + float angularVelocity = 0; + float thickness = 0; + float density = 0; + float rigidity = 0; + float temperature = 0; Eigen::Vector3f debugColor; - PlateType ptype; + PlateType ptype = PlateType::MIXED; + std::vector assignedNodes; }; class planetsim { @@ -235,7 +238,17 @@ public: plates[i].plateId = i; config.surfaceNodes[seedIndex].plateID = i; float colorVal = static_cast(seedid) / config.surfaceNodes.size(); - plates[i].debugColor = v3(colorVal,colorVal,colorVal); + if (i % 3 == 0) { + float r = static_cast(seedid * seedid) / config.surfaceNodes.size(); + plates[i].debugColor = v3(r, colorVal, colorVal); + } else if (i % 3 == 1) { + float g = static_cast(seedid * seedid) / config.surfaceNodes.size(); + plates[i].debugColor = v3(colorVal, g, colorVal); + } else { + float b = static_cast(seedid * seedid) / config.surfaceNodes.size(); + plates[i].debugColor = v3(colorVal, colorVal, b); + } + foundValidSeed = true; } @@ -246,39 +259,89 @@ public: selectedSeedIndices.push_back(seedIndex); plates[i].plateId = i; float colorVal = static_cast(seedIndex) / config.surfaceNodes.size(); - plates[i].debugColor = v3(colorVal,colorVal,colorVal); + if (i % 3 == 0) { + float r = static_cast(seedid * seedid) / config.surfaceNodes.size(); + plates[i].debugColor = v3(r, colorVal, colorVal); + } else if (i % 3 == 1) { + float g = static_cast(seedid * seedid) / config.surfaceNodes.size(); + plates[i].debugColor = v3(colorVal, g, colorVal); + } else { + float b = static_cast(seedid * seedid) / config.surfaceNodes.size(); + plates[i].debugColor = v3(colorVal, colorVal, b); + } config.surfaceNodes[seedIndex].plateID = i; } } } - void buildAdjacencyList() { TIME_FUNCTION; for (int i = 0; i < config.surfaceNodes.size(); i++) { - Particle in = config.surfaceNodes[i]; - v3 inn = in.basePos.normalized(); - for (int j = 1; j < config.surfaceNodes.size(); j++) { - if (i == j) { - continue; - } - auto ij = config.surfaceNodes[j]; - if (ij.neighbors.contains(i)){ - in.neighbors[j] = ij.neighbors[i]; - } + Particle& in = config.surfaceNodes[i]; + int test_idx = 0; + if (test_idx == i) test_idx++; + float current_radius = (in.basePos - config.surfaceNodes[test_idx].basePos).norm(); + in.neighbors[test_idx] = current_radius; + std::vector> valid_results; - v3 ijn = ij.basePos.normalized(); - float cosangle = inn.dot(ijn); - float angle = std::acos(cosangle); + int safety_counter = 0; + while (safety_counter++ < 1000) { + auto results = grid.findInRadius(in.basePos, current_radius); + valid_results.clear(); + valid_results.reserve(results.size()); + + for (const auto& node : results) { + int j = node->subId; + if (i == j) continue; + float dist = (in.basePos - node->position).norm(); + in.neighbors[j] = dist; + valid_results.push_back({dist, j}); + } - in.neighbors[j] = angle; + int count = valid_results.size(); + + if (count < 8) { + test_idx++; + if (test_idx == i) test_idx++; + if (test_idx >= config.surfaceNodes.size()) break; + + current_radius = (in.basePos - config.surfaceNodes[test_idx].basePos).norm(); + in.neighbors[test_idx] = current_radius; + } + else if (count > 16) { + float new_radius = valid_results[0].first; + if (new_radius >= current_radius || new_radius == 0.0f) { + current_radius *= 0.9f; + } else { + current_radius = new_radius; + } + } + } + + std::sort(valid_results.begin(), valid_results.end()); + + int max_neighbors = std::min(8, (int)valid_results.size()); + for (int k = 0; k < max_neighbors; k++) { + in.nearNeighbors[valid_results[k].first] = valid_results[k].second; } } } void growPlatesRandom() { TIME_FUNCTION; + std::uniform_int_distribution distPlate(0, config.numPlates); + std::vector unassigned; + for (int i = 0; i < config.surfaceNodes.size(); i++) { + if (config.surfaceNodes[i].plateID != -1) + unassigned.emplace_back(i); + else plates[config.surfaceNodes[i].plateID].assignedNodes.emplace_back(i); + } + + while (!unassigned.empty()) { + int selPlate = distPlate(rng); + + } } void growPlatesCellular() {