WIP: introduce rank/dim/grade template parameters

This commit is contained in:
David Allemang
2023-02-12 09:26:15 -05:00
parent 53fe3104db
commit ad0ee7df08
2 changed files with 23 additions and 18 deletions

View File

@@ -18,21 +18,25 @@
#include <shaders.hpp>
namespace vis {
template<int N>
template<int R_, int D_, int G_>
struct Structure {
using Affine4f = Eigen::Transform<float, 4, Eigen::Affine>;
static constexpr auto Rank = R_;
static constexpr auto Dim = D_;
static constexpr auto Grade = G_;
using Vertex = Eigen::Vector<float, 4>;
using Affine = Eigen::Transform<float, Dim, Eigen::Affine>;
using Vertex = Eigen::Vector<float, Dim>;
using Color = Eigen::Vector<float, 3>;
using Cell = Eigen::Array<unsigned int, 4, 1>;
using Cell = Eigen::Array<unsigned int, Grade, 1>;
Points points;
Hull<N> hull;
Hull <Grade> hull;
std::vector<char> enabled;
std::vector<Eigen::Vector3f> colors;
Affine4f transform = Affine4f::Identity();
Affine transform = Affine::Identity();
template<typename P, typename H>
explicit Structure(P &&points_, H &&hull_, Color color_ = Color::Ones()):
@@ -40,8 +44,7 @@ namespace vis {
hull(std::forward<H>(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<Structure<4>::Vertex> vertices;
cgl::Buffer<Structure<4>::Color> colors;
cgl::Buffer<Structure<4>::Cell> indices;
cgl::Buffer<Structure<5, 4, 4>::Vertex> vertices;
cgl::Buffer<Structure<5, 4, 4>::Color> colors;
cgl::Buffer<Structure<5, 4, 4>::Cell> indices;
cgl::Buffer<Uniform> uniform;
cgl::Buffer<Command> commands;
};
void upload_structure(entt::registry &registry) {
auto view = registry.view<Structure<4>, VBOs>();
auto view = registry.view<Structure<5, 4, 4>, 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 &registry) {
auto view = registry.view<Structure<4>, VBOs>();
auto view = registry.view<Structure<5, 4, 4>, VBOs>();
for (auto [entity, structure, vbos]: view.each()) {
auto colors = structure.colors;
@@ -90,7 +93,7 @@ namespace vis {
}
void upload_commands(entt::registry &registry) {
auto view = registry.view<Structure<4>, VBOs>();
auto view = registry.view<Structure<5, 4, 4>, VBOs>();
for (auto [entity, structure, vbos]: view.each()) {
const auto &tilings = structure.hull.tilings;

View File

@@ -109,7 +109,7 @@ void show_overlay(State &state) {
}
void show_options(entt::registry &registry) {
auto view = registry.view<vis::Structure<4>>();
auto view = registry.view<vis::Structure<5, 4, 4>>();
for (auto [entity, structure]: view.each()) {
ImGui::Begin("Structure View Options");
@@ -153,16 +153,18 @@ int run(GLFWwindow* window, ImGuiContext* ctx) {
auto &registry = 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<vis::Structure<4>>(entity, std::move(points), std::move(hull));
auto &structure = registry.emplace<Slice>(entity, std::move(points), std::move(hull));
registry.emplace<vis::VBOs>(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<vis::Structure<4>>(entity).transform;
auto &tform = registry.get<Slice>(entity).transform;
if (!io.KeysDown[GLFW_KEY_SPACE]) {
float speed = 1.0 / 8.0;