diff --git a/CMakeLists.txt b/CMakeLists.txt index aeeb06d..8f0f1bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,4 +41,4 @@ add_executable(combotest src/combotest.cpp) target_link_libraries(combotest eigen tc) add_executable(geometrytest src/geometrytest.cpp) -target_link_libraries(geometrytest eigen tc) +target_link_libraries(geometrytest eigen tc nlohmann_json) diff --git a/src/geometrytest.cpp b/src/geometrytest.cpp index e718a1a..c1e49ec 100644 --- a/src/geometrytest.cpp +++ b/src/geometrytest.cpp @@ -4,41 +4,59 @@ #include #include +#include +#include #include int main() { - std::vector symbol = {3, 4, 3, 2}; - vec5 root{0.80, 0.02, 0.02, 0.02, 0.02}; + std::vector symbol = {5, 3, 3}; + vec4 root{0.80, 0.02, 0.02, 0.02}; + auto group = tc::schlafli(symbol); auto gens = generators(group); - auto combos = combinations(gens, 3); + auto combos = combinations(gens, 2); - const auto &inds = merge<4>(hull<4>(group, combos, {})); + const auto &inds = merge<3>(hull<3>(group, combos, { + {0, 1}, + })); auto cosets = group.solve(); - auto mirrors = mirror<5>(group); + auto mirrors = mirror<4>(group); auto corners = plane_intersections(mirrors); auto start = barycentric(corners, root); - using Projective5f = Eigen::Transform; - Projective5f transform = Projective5f::Identity(); + using Projective = Eigen::Transform; + Projective transform = Projective::Identity(); - auto higher = cosets.path.walk(start, mirrors, reflect); + auto higher = cosets.path.walk(start, mirrors, reflect); std::transform( higher.begin(), higher.end(), higher.begin(), - [&](const vec5 &v) { + [&](const vec4 &v) { return (transform * v.homogeneous()).hnormalized(); } ); - std::vector lower(higher.size()); - std::transform(higher.begin(), higher.end(), lower.begin(), stereo<4>); +// std::vector lower(higher.size()); +// std::transform(higher.begin(), higher.end(), lower.begin(), stereo<4>); +// const auto &verts = lower; - const auto &verts = lower; + const auto &verts = higher; - std::cout << inds.rows() << " " << inds.cols() << std::endl; + using PT = Eigen::Matrix; + using CT = Eigen::Matrix; + + PT points(4, verts.size()); + std::copy(verts.begin(), verts.end(), points.colwise().begin()); + + CT cells = inds; + + std::cout << points.rows() << " " << points.cols() << std::endl; + std::cout << cells.rows() << " " << cells.cols() << std::endl; + + ml::Mesh mesh(points, cells); + ml::write(mesh, std::ofstream("dodeca.pak", std::ios::out | std::ios::binary)); return EXIT_SUCCESS; } diff --git a/src/main.cpp b/src/main.cpp index 26913d2..c5933fc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -127,31 +127,36 @@ int run(GLFWwindow *window, ImGuiContext *context) { State state; Buffer ind_buf; - Buffer vert_buf; + Buffer vert_buf; - Buffer ind4d_buf; - Buffer vert4d_buf; +// Buffer ind4d_buf; +// Buffer vert4d_buf; - VertexArray vao(vert_buf); + VertexArray vao(vert_buf); glVertexArrayElementBuffer(vao, ind_buf); - VertexArray vao4d(vert4d_buf); - glVertexArrayElementBuffer(vao4d, ind4d_buf); +// VertexArray vao4d(vert4d_buf); +// glVertexArrayElementBuffer(vao4d, ind4d_buf); - auto mesh = ml::make_cube(0.22f); + using PointsType = Eigen::Matrix; + using CellsType = Eigen::Matrix; + using Mesh = ml::Mesh; + + auto mesh = ml::read(std::ifstream("dodeca.pak")); +// auto mesh = ml::make_cube(0.22f); auto elements = (GLint) ind_buf.upload(mesh.cells.reshaped()); vert_buf.upload(mesh.points.colwise()); - auto mesh4d = ml::make_cube_wire<4>(0.33f); - auto elements4d = (GLint) ind4d_buf.upload(mesh4d.cells.reshaped()); - vert4d_buf.upload(mesh4d.points.colwise()); +// auto mesh4d = ml::make_cube_wire<4>(0.33f); +// auto elements4d = (GLint) ind4d_buf.upload(mesh4d.cells.reshaped()); +// vert4d_buf.upload(mesh4d.points.colwise()); - VertexShader vs(std::ifstream("res/shaders/main.vert.glsl")); +// VertexShader vs(std::ifstream("res/shaders/main.vert.glsl")); VertexShader vs4d(std::ifstream("res/shaders/4d.vert.glsl")); FragmentShader fs(std::ifstream("res/shaders/main.frag.glsl")); - Program pgm(vs, fs); - Program pgm4d(vs4d, fs); + Program pgm(vs4d, fs); +// Program pgm4d(vs4d, fs); glEnable(GL_DEPTH_TEST); @@ -173,7 +178,7 @@ int run(GLFWwindow *window, ImGuiContext *context) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); auto aspect = (float) display_h / (float) display_w; - proj = Eigen::AlignedScaling3f(aspect, 1.0, -1.0); + proj = Eigen::AlignedScaling3f(aspect, 1.0, -0.6); glUseProgram(pgm); glBindVertexArray(vao); @@ -185,34 +190,34 @@ int run(GLFWwindow *window, ImGuiContext *context) { glBindVertexArray(0); glUseProgram(0); - glUseProgram(pgm4d); - glBindVertexArray(vao4d); - glUniform4fv(0, 1, state.wf.data()); - glUniform1f(1, (GLfloat) glfwGetTime()); - glUniformMatrix4fv(2, 1, false, proj.data()); - glUniformMatrix4fv(3, 1, false, state.rot.data()); - - if (state.color_axes) { - auto factor = 0.7f; - auto x = mix(state.wf, state.R, factor); - auto y = mix(state.wf, state.G, factor); - auto z = mix(state.wf, state.B, factor); - auto w = mix(state.wf, state.Y, factor); - - glUniform4fv(0, 1, x.data()); - glDrawElementsBaseVertex(GL_LINES, 2, GL_UNSIGNED_INT, (void *) (sizeof(GLuint) * 0), 0); - glUniform4fv(0, 1, y.data()); - glDrawElementsBaseVertex(GL_LINES, 2, GL_UNSIGNED_INT, (void *) (sizeof(GLuint) * 2), 0); - glUniform4fv(0, 1, z.data()); - glDrawElementsBaseVertex(GL_LINES, 2, GL_UNSIGNED_INT, (void *) (sizeof(GLuint) * 8), 0); - glUniform4fv(0, 1, w.data()); - glDrawElementsBaseVertex(GL_LINES, 2, GL_UNSIGNED_INT, (void *) (sizeof(GLuint) * 24), 0); - } - - glUniform4fv(0, 1, state.wf.data()); - glDrawElements(GL_LINES, elements4d, GL_UNSIGNED_INT, nullptr); - glBindVertexArray(0); - glUseProgram(0); +// glUseProgram(pgm4d); +// glBindVertexArray(vao4d); +// glUniform4fv(0, 1, state.wf.data()); +// glUniform1f(1, (GLfloat) glfwGetTime()); +// glUniformMatrix4fv(2, 1, false, proj.data()); +// glUniformMatrix4fv(3, 1, false, state.rot.data()); +// +// if (state.color_axes) { +// auto factor = 0.7f; +// auto x = mix(state.wf, state.R, factor); +// auto y = mix(state.wf, state.G, factor); +// auto z = mix(state.wf, state.B, factor); +// auto w = mix(state.wf, state.Y, factor); +// +// glUniform4fv(0, 1, x.data()); +// glDrawElementsBaseVertex(GL_LINES, 2, GL_UNSIGNED_INT, (void *) (sizeof(GLuint) * 0), 0); +// glUniform4fv(0, 1, y.data()); +// glDrawElementsBaseVertex(GL_LINES, 2, GL_UNSIGNED_INT, (void *) (sizeof(GLuint) * 2), 0); +// glUniform4fv(0, 1, z.data()); +// glDrawElementsBaseVertex(GL_LINES, 2, GL_UNSIGNED_INT, (void *) (sizeof(GLuint) * 8), 0); +// glUniform4fv(0, 1, w.data()); +// glDrawElementsBaseVertex(GL_LINES, 2, GL_UNSIGNED_INT, (void *) (sizeof(GLuint) * 24), 0); +// } +// +// glUniform4fv(0, 1, state.wf.data()); +// glDrawElements(GL_LINES, elements4d, GL_UNSIGNED_INT, nullptr); +// glBindVertexArray(0); +// glUseProgram(0); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); glfwSwapBuffers(window);