diff --git a/cosets/CMakeLists.txt b/cosets/CMakeLists.txt index 4e40d31..e157ee6 100644 --- a/cosets/CMakeLists.txt +++ b/cosets/CMakeLists.txt @@ -16,3 +16,5 @@ add_custom_command( add_executable(coxeter src/coxeter.cpp) add_executable(mirror src/mirrors.cpp) target_link_libraries(mirror PRIVATE glm) +add_executable(mesh src/mesh.cpp) +target_link_libraries(mesh PRIVATE glm) diff --git a/cosets/src/main.cpp b/cosets/src/main.cpp index de0e007..c7e7c88 100644 --- a/cosets/src/main.cpp +++ b/cosets/src/main.cpp @@ -5,6 +5,9 @@ #include #include #include +#include + +#include "util/mesh.hpp" using namespace std; @@ -13,7 +16,7 @@ class CosetsWindow : public Window { GLuint tri; GLuint verts; - static const unsigned VERTS_N = 8; + std::vector verts_data; public: void init() override { @@ -29,21 +32,16 @@ public: program = build_program("main", vs, fs); - glm::vec4 verts_data[VERTS_N]{ - {+0.5, +0.5, +0.5, +0.0}, - {+0.5, -0.5, +0.5, +0.0}, - {-0.5, -0.5, +0.5, +0.0}, - {-0.5, +0.5, +0.5, +0.0}, - - {+0.5, +0.5, +0.5, -0.5}, - {+0.5, -0.5, +0.5, -0.5}, - {-0.5, -0.5, +0.5, +0.5}, - {-0.5, +0.5, +0.5, +0.5}, - }; + verts_data = vertices<3>({}, Multiplicites<3>({ + {0, 1, 4}, + {1, 2, 3} + }), { + 2.0f, .05f, 0.05f + }); glGenBuffers(1, &verts); glBindBuffer(GL_ARRAY_BUFFER, verts); - glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 4 * VERTS_N, verts_data, GL_STATIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, sizeof(glm::vec4) * verts_data.size(), &verts_data[0], GL_STATIC_DRAW); glGenVertexArrays(1, &tri); @@ -78,7 +76,7 @@ public: glPointSize(10.f); glBindVertexArray(tri); - glDrawArrays(GL_POINTS, 0, VERTS_N); + glDrawArrays(GL_POINTS, 0, verts_data.size()); swapbuffers(); } diff --git a/cosets/src/mesh.cpp b/cosets/src/mesh.cpp new file mode 100644 index 0000000..eb26070 --- /dev/null +++ b/cosets/src/mesh.cpp @@ -0,0 +1,16 @@ +#include "util/mesh.hpp" + +int main(int argc, char *argv[]) { + auto vs = vertices<3>({}, Multiplicites<3>({ + {0, 1, 4}, + {1, 2, 3} + }), { + 1.0f, 1.0f, 1.0f + }); + + for (const auto &v : vs) { + std::cout << glm::to_string(v) << std::endl; + } + + return 0; +} \ No newline at end of file diff --git a/cosets/src/util/mesh.hpp b/cosets/src/util/mesh.hpp new file mode 100644 index 0000000..5879526 --- /dev/null +++ b/cosets/src/util/mesh.hpp @@ -0,0 +1,60 @@ +#pragma once + +#include "coxeter.hpp" +#include "mirrors.hpp" +#include "numeric.hpp" + +#include + +template +std::vector +vertices(const std::vector &subgens, const Multiplicites &mults, const float (&coords)[N]) { + std::vector> rels{}; + rels.reserve(N + N * (N - 1) / 2); + + for (int i = 0; i < N; ++i) { + rels.push_back({i, i}); + } + for (int a = 0; a < N; ++a) { + for (int b = 0; b < a; ++b) { + int mult = mults.get(a, b); + + std::vector rel{}; + for (int i = 0; i < mult; ++i) { + rel.push_back(a); + rel.push_back(b); + } + rels.push_back(rel); + } + } + + Table *table = solve(N, subgens, rels); + +// std::cout << table->size() << std::endl; +// std::cout << *table << std::endl; + +// for (const auto &v : table->words()) { +// std::cout << "[ "; +// for (auto e : v) { +// std::cout << e << " "; +// } +// std::cout << "]\n"; +// } + + const std::vector &normals = mirror<3>(mults); + const std::vector &corners = plane_intersections(normals); + const std::vector coords_vec(coords, coords + N); + const glm::vec4 &identity = glm::normalize(barycentric(corners, coords_vec)); + + std::vector verts(table->size()); + + for (const auto &word : table->words()) { + glm::vec4 vert = identity; + for (const auto &gen : word) { + vert = reflect(vert, normals[gen]); + } + verts.push_back(vert); + } + + return verts; +} \ No newline at end of file diff --git a/cosets/src/util/numeric.hpp b/cosets/src/util/numeric.hpp index d4a749f..b787c08 100644 --- a/cosets/src/util/numeric.hpp +++ b/cosets/src/util/numeric.hpp @@ -51,7 +51,7 @@ std::vector plane_intersections(std::vector normals) { std::vector results(N); for (int i = 0; i < N; ++i) { - results[i] = gram_schmidt_last(normals); + results[i] = glm::normalize(gram_schmidt_last(normals)); std::rotate(normals.begin(), normals.begin() + 1, normals.end()); }