From ad0ee7df083dfe5f3196381d44d8abedcdf3178c Mon Sep 17 00:00:00 2001 From: David Allemang Date: Sun, 12 Feb 2023 09:26:15 -0500 Subject: [PATCH] WIP: introduce rank/dim/grade template parameters --- vis/src/comps.hpp | 31 +++++++++++++++++-------------- vis/src/main.cpp | 10 ++++++---- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/vis/src/comps.hpp b/vis/src/comps.hpp index 82f4470..12c19bf 100644 --- a/vis/src/comps.hpp +++ b/vis/src/comps.hpp @@ -18,21 +18,25 @@ #include namespace vis { - template + template struct Structure { - using Affine4f = Eigen::Transform; + static constexpr auto Rank = R_; + static constexpr auto Dim = D_; + static constexpr auto Grade = G_; - using Vertex = Eigen::Vector; + using Affine = Eigen::Transform; + + using Vertex = Eigen::Vector; using Color = Eigen::Vector; - using Cell = Eigen::Array; + using Cell = Eigen::Array; Points points; - Hull hull; + Hull hull; std::vector enabled; std::vector colors; - Affine4f transform = Affine4f::Identity(); + Affine transform = Affine::Identity(); template explicit Structure(P &&points_, H &&hull_, Color color_ = Color::Ones()): @@ -40,8 +44,7 @@ namespace vis { hull(std::forward(hull_)), enabled(hull.tilings.size(), true), colors(hull.tilings.size(), color_), - transform(Affine4f::Identity()) { - + transform(Affine::Identity()) { } }; @@ -55,15 +58,15 @@ namespace vis { unsigned int count, instanceCount, first, baseInstance; }; - cgl::Buffer::Vertex> vertices; - cgl::Buffer::Color> colors; - cgl::Buffer::Cell> indices; + cgl::Buffer::Vertex> vertices; + cgl::Buffer::Color> colors; + cgl::Buffer::Cell> indices; cgl::Buffer uniform; cgl::Buffer commands; }; void upload_structure(entt::registry ®istry) { - auto view = registry.view, VBOs>(); + auto view = registry.view, VBOs>(); for (auto [entity, structure, vbos]: view.each()) { auto vertices = structure.points.verts.colwise(); @@ -75,7 +78,7 @@ namespace vis { } void upload_uniforms(entt::registry ®istry) { - auto view = registry.view, VBOs>(); + auto view = registry.view, VBOs>(); for (auto [entity, structure, vbos]: view.each()) { auto colors = structure.colors; @@ -90,7 +93,7 @@ namespace vis { } void upload_commands(entt::registry ®istry) { - auto view = registry.view, VBOs>(); + auto view = registry.view, VBOs>(); for (auto [entity, structure, vbos]: view.each()) { const auto &tilings = structure.hull.tilings; diff --git a/vis/src/main.cpp b/vis/src/main.cpp index 151d40a..32b8b48 100644 --- a/vis/src/main.cpp +++ b/vis/src/main.cpp @@ -109,7 +109,7 @@ void show_overlay(State &state) { } void show_options(entt::registry ®istry) { - auto view = registry.view>(); + auto view = registry.view>(); for (auto [entity, structure]: view.each()) { ImGui::Begin("Structure View Options"); @@ -153,16 +153,18 @@ int run(GLFWwindow* window, ImGuiContext* ctx) { auto ®istry = state.registry; state.dimension = 4; + using Slice = vis::Structure<5, 4, 4>; + auto entity = registry.create(); { // todo move symbol and root to structure // cache and recompute cells/points on frame (only if changed) in a system. tc::Group group = tc::schlafli({5, 3, 3, 2}); - Points points(group, vec5{0.80, 0.3, 0.15, 0.15, 0.03}); + Points points(group, vec5{0.80, 0.09, 0.09, 0.09, 0.09}); Hull<4> hull(group); - auto& structure = registry.emplace>(entity, std::move(points), std::move(hull)); + auto &structure = registry.emplace(entity, std::move(points), std::move(hull)); registry.emplace(entity); structure.enabled[0] = false; // disable {0,1,2} cells @@ -199,7 +201,7 @@ int run(GLFWwindow* window, ImGuiContext* ctx) { ubo.put(build(window, state, ctx), GL_STREAM_DRAW); { - auto &tform = registry.get>(entity).transform; + auto &tform = registry.get(entity).transform; if (!io.KeysDown[GLFW_KEY_SPACE]) { float speed = 1.0 / 8.0;