diff --git a/vis/include/geometry.hpp b/vis/include/geometry.hpp index a8e62b2..8f4f7bb 100644 --- a/vis/include/geometry.hpp +++ b/vis/include/geometry.hpp @@ -26,6 +26,10 @@ struct Primitive { inds[N - 1] = root; } + explicit Primitive(const std::vector &values) { + std::copy(values.begin(), values.begin() + N, inds.begin()); + } + ~Primitive() = default; void apply(const tc::Cosets &table, int gen) { diff --git a/vis/src/main-gui.cpp b/vis/src/main-gui.cpp index 83750ca..99f0e6d 100644 --- a/vis/src/main-gui.cpp +++ b/vis/src/main-gui.cpp @@ -39,10 +39,6 @@ struct Matrices { auto pwidth = aspect * pheight; mat4 proj = ortho(-pwidth, pwidth, -pheight, pheight, -10.0f, 10.0f); -// if (!glfwGetKey(window, GLFW_KEY_LEFT_SHIFT)) { -// state.st += state.time_delta / 8; -// } - auto view = mat4::Identity(); return Matrices(proj, view); } @@ -138,7 +134,6 @@ public: prop = std::make_unique>(make_slice<4>(*group, root, {}, combos, exclude)); ubo = std::make_unique>(); - glBindBufferBase(GL_UNIFORM_BUFFER, 1, *ubo); ren = std::make_unique>(); } @@ -162,6 +157,7 @@ public: std::get<0>(prop->vbos).put(points(*group, root, time)); Matrices mats = Matrices::build(*this); + glBindBufferBase(GL_UNIFORM_BUFFER, 1, *ubo); ubo->put(mats); ren->draw(*prop); } diff --git a/vis/src/main.cpp b/vis/src/main.cpp deleted file mode 100644 index a06a85d..0000000 --- a/vis/src/main.cpp +++ /dev/null @@ -1,196 +0,0 @@ -#include -#include - -#include -#include -#include -#include - -#include - -#include - -#include -#include -#include - -#include -#include -#include -#include -#include - -#ifdef _WIN32 -extern "C" { -__attribute__((unused)) __declspec(dllexport) int NvOptimusEnablement = 0x00000001; -} -#endif - -struct Matrices { - mat4 proj; - mat4 view; - - Matrices() = default; - - Matrices(const mat4 &proj, const mat4 &view) - : proj(proj), view(view) { - } -}; - -struct State { - float time; - float time_delta; - - float st; - - int dimension; -}; - -Matrices build(GLFWwindow *window, State &state) { - int width, height; - glfwGetFramebufferSize(window, &width, &height); - - auto aspect = (float) width / (float) height; - auto pheight = 1.4f; - auto pwidth = aspect * pheight; - mat4 proj = ortho(-pwidth, pwidth, -pheight, pheight, -10.0f, 10.0f); - - if (!glfwGetKey(window, GLFW_KEY_LEFT_SHIFT)) { - state.st += state.time_delta / 8; - } - - auto view = identity<4>(); - return Matrices(proj, view); -} - -template -std::vector points(const tc::Group &group, const C &coords, const float time) { - auto cosets = group.solve(); - auto mirrors = mirror<5>(group); - - auto corners = plane_intersections(mirrors); - auto start = barycentric(corners, coords); - - auto higher = cosets.path.walk(start, mirrors, reflect); - - auto r = identity<5>(); - r = mul(r, rot<5>(0, 2, time * .21f)); - r = mul(r, rot<5>(1, 4, time * .27f)); - - r = mul(r, rot<5>(0, 3, time * .17f)); - r = mul(r, rot<5>(1, 3, time * .25f)); - r = mul(r, rot<5>(2, 3, time * .12f)); - - std::transform(higher.begin(), higher.end(), higher.begin(), [&](vec5 v) { return mul(v, r); }); - - std::vector lower(higher.size()); - std::transform(higher.begin(), higher.end(), lower.begin(), stereo<4>); - return lower; -} - -template -Prop<4, vec4> make_slice( - const tc::Group &g, - const C &coords, - vec3 color, - T all_sg_gens, - const std::vector> &exclude -) { - Prop res{}; - -// res.vbo.put(points(g, coords)); - res.ibo.put(merge(hull(g, all_sg_gens, exclude))); - res.vao.ipointer(0, res.ibo, 4, GL_UNSIGNED_INT); - - return res; -} - -void run(const std::string &config_file, GLFWwindow *window) { - glEnable(GL_DEPTH_TEST); - - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - std::vector symbol = {4, 3, 3, 3}; - vec5 root = {.80, .02, .02, .02, .02}; - - auto group = tc::schlafli(symbol); - auto gens = generators(group); - std::vector> exclude = {{0, 1, 2}}; - auto combos = Combos(gens, 3); - - SliceRenderer<4, vec4> ren{}; - Prop<4, vec4> prop = make_slice<4>(group, root, {}, combos, exclude); - - State state{}; - state.dimension = 4; - glfwSetWindowUserPointer(window, &state); - - auto ubo = cgl::Buffer(); - glBindBufferBase(GL_UNIFORM_BUFFER, 1, ubo); - - while (!glfwWindowShouldClose(window)) { - auto time = (float) glfwGetTime(); - state.time_delta = state.time - time; - state.time = time; - - int width, height; - glfwGetFramebufferSize(window, &width, &height); - - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - glLineWidth(1.5); - - std::get<0>(prop.vbos).put(points(group, root, time)); - - Matrices mats{}; - - glViewport(0, 0, width, height); - mats = build(window, state); - ubo.put(mats); - ren.draw(prop); - - glfwSwapInterval(2); - glfwSwapBuffers(window); - - glfwPollEvents(); - } -} - -int main(int argc, char *argv[]) { - if (!glfwInit()) { - std::cerr << "Failed to initialize GLFW" << std::endl; - return EXIT_FAILURE; - } - - glfwWindowHint(GLFW_VERSION_MAJOR, 4); - glfwWindowHint(GLFW_VERSION_MAJOR, 5); -// glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); - - auto window = glfwCreateWindow( - 1920, 1080, - "Coset Visualization", - nullptr, nullptr); - - if (!window) { - std::cerr << "Failed to create window" << std::endl; - glfwTerminate(); - exit(EXIT_FAILURE); - } - - glfwMakeContextCurrent(window); - gladLoadGLLoader((GLADloadproc) glfwGetProcAddress); - glfwSwapInterval(1); - glClear(GL_COLOR_BUFFER_BIT); - glfwSwapBuffers(window); - - std::cout << utilInfo(); - - std::string config_file = "presets/default.yaml"; - if (argc > 1) config_file = std::string(argv[1]); - - run(config_file, window); - - glfwTerminate(); - return EXIT_SUCCESS; -}