diff --git a/vis/include/mirror.hpp b/vis/include/mirror.hpp index c7fc67b..8402411 100644 --- a/vis/include/mirror.hpp +++ b/vis/include/mirror.hpp @@ -15,6 +15,15 @@ using vec3 = vec<3>; using vec4 = vec<4>; using vec5 = vec<5>; +template +using mat = std::array, N>; + +using mat1 = mat<1>; +using mat2 = mat<2>; +using mat3 = mat<3>; +using mat4 = mat<4>; +using mat5 = mat<5>; + template V operator*(V a, const float &b) { for (auto &e : a) e *= b; @@ -93,6 +102,30 @@ float dot(const V &a, const V &b) { return sum; } +vec5 mul(vec5 v, mat5 m) { + vec5 r{}; + + for (int i = 0; i < 5; ++i) + for (int j = 0; j < 5; ++j) + r[i] += m[i][j] * v[j]; + + return r; +} + +mat5 mul(mat5 a, mat5 b) { + mat5 r{}; + + for (int i = 0; i < 5; ++i) { + for (int j = 0; j < 5; ++j) { + for (int k = 0; k < 5; ++k) { + r[i][j] += a[i][k] * b[k][j]; + } + } + } + + return r; +} + template std::vector> mirror(const tc::Group &group) { std::vector> mirrors; @@ -140,6 +173,15 @@ vec stereo(const vec &v) { return r; } +template +vec ortho(const vec &v) { + vec r; + for (int i = 0; i < N; ++i) { + r[i] = v[i]; + } + return r; +} + template V project(const V &vec, const V &target) { return dot(vec, target) / dot(target, target) * target; @@ -191,4 +233,22 @@ glm::mat4 utilRotate(const int u, const int v, const float theta) { res[v][u] = -std::sin(theta); res[v][v] = std::cos(theta); return res; +} + +template +mat identity() { + mat res{}; + for (int i = 0; i < N; ++i) + res[i][i] = 1; + return res; +} + +template +mat rot(int u, int v, float theta) { + auto res = identity(); + res[u][u] = std::cos(theta); + res[u][v] = std::sin(theta); + res[v][u] = -std::sin(theta); + res[v][v] = std::cos(theta); + return res; } \ No newline at end of file diff --git a/vis/src/main.cpp b/vis/src/main.cpp index 23ea52b..1675ae4 100644 --- a/vis/src/main.cpp +++ b/vis/src/main.cpp @@ -31,6 +31,8 @@ struct Matrices { glm::mat4 proj; glm::mat4 view; + Matrices() = default; + Matrices(const glm::mat4 &proj, const glm::mat4 &view) : proj(proj), view(view) { } @@ -45,49 +47,49 @@ struct State { int dimension; }; -Matrices build(GLFWwindow *window, State &state) { +Matrices build(GLFWwindow *window, State &state, float shift = 0.0) { int width, height; glfwGetFramebufferSize(window, &width, &height); - auto aspect = (float) width / (float) height; + auto aspect = (float) width / (float) height / 2; auto pheight = 1.4f; auto pwidth = aspect * pheight; glm::mat4 proj = glm::ortho(-pwidth, pwidth, -pheight, pheight, -10.0f, 10.0f); + glm::mat4 skew = glm::mat4( + 1, 0, 0, 0, + 0, 1, 0, 0, + shift, 0, 1, 0, + 0, 0, 0, 1 + ); if (!glfwGetKey(window, GLFW_KEY_LEFT_SHIFT)) { state.st += state.time_delta / 8; } auto view = glm::identity(); - if (state.dimension < 4) { - view *= utilRotate(2, 3, M_PI_2f32 + 0.01f); - } - - if (state.dimension > 1) { - view *= utilRotate(0, 1, state.st * .40f); - } - if (state.dimension > 2) { - view *= utilRotate(0, 2, state.st * .20f); - view *= utilRotate(1, 2, state.st * .50f); - } - if (state.dimension > 3) { - view *= utilRotate(0, 3, state.st * 1.30f); - view *= utilRotate(1, 3, state.st * .25f); - view *= utilRotate(2, 3, state.st * 1.42f); - } - - return Matrices(proj, view); + return Matrices(skew * proj, view); } template -std::vector points(const tc::Group &group, const C &coords) { +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); - const auto &higher = cosets.path.walk(start, mirrors, reflect); + 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; @@ -103,7 +105,7 @@ Prop<4, vec4> make_slice( ) { Prop res{}; - res.vbo.put(points(g, coords)); +// 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); @@ -116,8 +118,8 @@ void run(const std::string &config_file, GLFWwindow *window) { glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - std::vector symbol = {5, 3, 3, 2}; - vec5 root = {.80, .09, .09, 0.09, 0.03}; + std::vector symbol = {4, 3, 3, 3}; + vec5 root = {.80, .02, .02, .02, .02}; auto group = tc::schlafli(symbol); auto gens = generators(group); @@ -262,15 +264,25 @@ void run(const std::string &config_file, GLFWwindow *window) { int width, height; glfwGetFramebufferSize(window, &width, &height); - glViewport(0, 0, width, height); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - Matrices mats = build(window, state); - ubo.put(mats); - glLineWidth(1.5); + prop.vbo.put(points(group, root, time)); + + Matrices mats{}; + + float shift = .3f; + + glViewport(0, 0, width / 2, height); + mats = build(window, state, shift); + ubo.put(mats); + ren.draw(prop); + + glViewport(width / 2, 0, width / 2, height); + mats = build(window, state, -shift); + ubo.put(mats); ren.draw(prop); //region old renderers