From 12b81919875f0694801adb596a336c4adf8d67e4 Mon Sep 17 00:00:00 2001 From: Jacob Date: Wed, 22 Jan 2020 02:09:45 -0500 Subject: [PATCH] Add dynamic rotations (in 4d) Make simplexes argument to geometry generation functions const Setup really cool looking parameters --- vis/include/geometry.hpp | 6 ++-- vis/src/main.cpp | 74 ++++++++++++++++++++++++++++++++-------- 2 files changed, 62 insertions(+), 18 deletions(-) diff --git a/vis/include/geometry.hpp b/vis/include/geometry.hpp index 51f1ff5..b06642d 100644 --- a/vis/include/geometry.hpp +++ b/vis/include/geometry.hpp @@ -33,7 +33,7 @@ struct Simplexes { Simplexes(int dim, std::vector &vals): dim(dim), vals(vals) {} explicit Simplexes(SimplexesList sl); - size_t size() { + size_t size() const { return vals.size(); } }; @@ -136,7 +136,7 @@ struct GeomGen { return solve_sg(sg_gens); } - Simplexes recontext(std::vector &g_gens, std::vector &sg_gens, Simplexes &items) { + Simplexes recontext(std::vector &g_gens, std::vector &sg_gens, const Simplexes &items) { auto s_sg_gens = prepare_gens(g_gens, sg_gens); auto table = solve_g(g_gens); auto path = solve_g(sg_gens).path; @@ -153,7 +153,7 @@ struct GeomGen { return ret; } - Simplexes tile(std::vector &g_gens, std::vector &sg_gens, Simplexes &items) { + Simplexes tile(std::vector &g_gens, std::vector &sg_gens, const Simplexes &items) { Simplexes base = recontext(g_gens, sg_gens, items); auto s_sg_gens = prepare_gens(g_gens, sg_gens); auto table = solve_g(g_gens); diff --git a/vis/src/main.cpp b/vis/src/main.cpp index 8e259d5..6715ccb 100644 --- a/vis/src/main.cpp +++ b/vis/src/main.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include @@ -17,6 +18,13 @@ __attribute__((unused)) __declspec(dllexport) int NvOptimusEnablement = 0x000000 } #endif +float floatmod(float x, float m) { + if (x < 0) { + x += (float)((int)((-x)/m) + 1)*m; + } + return x - ((float)((int)(x / m)))*m; +} + int main(int argc, char *argv[]) { //region init window @@ -59,8 +67,8 @@ int main(int argc, char *argv[]) { // utilCompileFiles(GL_VERTEX_SHADER, {"shaders/ortho.vs.glsl"}), // utilCompileFiles(GL_VERTEX_SHADER, {"shaders/stereo.vs.glsl"}), utilCompileFiles(GL_GEOMETRY_SHADER, {"shaders/stereo-proper.gm.glsl"}), -// utilCompileFiles(GL_FRAGMENT_SHADER, {"shaders/one-color.fs.glsl"}), - utilCompileFiles(GL_FRAGMENT_SHADER, {"shaders/w-axis-hue.fs.glsl"}) + utilCompileFiles(GL_FRAGMENT_SHADER, {"shaders/one-color.fs.glsl"}), +// utilCompileFiles(GL_FRAGMENT_SHADER, {"shaders/w-axis-hue.fs.glsl"}) }); } catch (const gl_error &e) { std::cerr << e.what() << std::endl; @@ -68,16 +76,18 @@ int main(int argc, char *argv[]) { exit(EXIT_FAILURE); } - auto group = tc::group::H(3)*tc::group::H(2); + auto group = tc::group::H(4); +// auto group = tc::group::B(5); +// auto group = tc::group::A(5); GeomGen gg(group); auto res = gg.solve(); auto mirrors = mirror(group); auto corners = plane_intersections(mirrors); - auto start = barycentric(corners, {1.00f, 1.00f, 0.05, 1.00f}); -// auto start = barycentric(corners, {1.00f, 0.05f, 0.05f, 0.05f}); +// auto start = barycentric(corners, {.75f, .75f, .75f, .75f}); + auto start = barycentric(corners, {1.00f, 0.1f, 0.01f, 0.005f}); // auto start = barycentric(corners, {1, 1, 0.05, 1}); - auto points = res.path.walk(start, mirrors, reflect_scaled); + auto points = res.path.walk(start, mirrors, reflect); GLuint vbo; glGenBuffers(1, &vbo); @@ -91,12 +101,14 @@ int main(int argc, char *argv[]) { std::vector edge_ibo; Simplexes base(1); base.vals = {0,1}; - auto g_gens = gg.group_gens(); + std::vector g_gens = gg.group_gens(); - for (int i = 0; i < group.ngens; i++) { + printf("Num Edges:\n"); + for (const auto i : g_gens) { std::vector sg_gens = {i}; const auto data = gg.tile(g_gens, sg_gens, base).vals; edge_count.push_back(data.size()); + printf("\t%d: %d", i, data.size()); GLuint ibo; glGenBuffers(1, &ibo); @@ -107,6 +119,27 @@ int main(int argc, char *argv[]) { glBindBuffer(GL_ARRAY_BUFFER, 0); + size_t numts = 7; + float rates[numts]; + rates[0] = 1.237; + rates[1] = 2.439; + rates[2] = 5.683; + rates[3] = -3.796; + rates[4] = 0.787; + rates[5] = -1.893; + rates[6] = 3.699; + + float _ts[numts]; + float _ts_temp[numts]; + for (int i = 0; i < numts; ++i) { + _ts[i] = ((float)i - (numts/2.f))*0.1f; + } + float* ts = _ts; + float* ts_temp = _ts_temp; + float* swap_t; + float alpha = 0.0001; + float beta = 0.0002; + while (!glfwWindowShouldClose(window)) { int width, height; glfwGetFramebufferSize(window, &width, &height); @@ -127,14 +160,25 @@ int main(int argc, char *argv[]) { glm::mat4 proj = glm::ortho(-pwidth, pwidth, -pheight, pheight, -10.0f, 10.0f); glUniformMatrix4fv(0, 1, false, glm::value_ptr(proj)); - auto t = (float) glfwGetTime() / 3; + auto st = (float) glfwGetTime() / 8; + auto t = st / 7; +// printf("ts: [%f", ts[0]); + ts_temp[0] = ts[0] + alpha * (float)std::cos(rates[0] * t) + beta * (-ts[0]); + for (size_t i = 1; i < numts; i++){ +// printf( ", %f", ts[i]); + ts_temp[i] = ts[i] + alpha * (float)std::cos(rates[i] * t) + beta * (-ts[i]); + } +// printf("]\n"); + swap_t = ts; + ts = ts_temp; + ts_temp = swap_t; auto view = glm::identity(); - view *= utilRotate(0, 1, t * 0.8f); - view *= utilRotate(0, 2, t * 0.9f); - view *= utilRotate(0, 3, t * 1.0f); - view *= utilRotate(1, 2, -t * 1.1f); - view *= utilRotate(1, 3, -t * 1.2f); - view *= utilRotate(2, 3, -t * 1.3f); + view *= utilRotate(0, 1, st * ts[0]); + view *= utilRotate(0, 2, st * ts[1]); + view *= utilRotate(0, 3, st * ts[2]); + view *= utilRotate(1, 2, st * ts[3]); + view *= utilRotate(1, 3, st * ts[4]); + view *= utilRotate(2, 3, st * ts[5]); glUniformMatrix4fv(1, 1, false, glm::value_ptr(view)); //endregion