basic 5d rotations; crossview

This commit is contained in:
2020-05-27 17:40:11 -04:00
parent 05d4314cec
commit 7c1f1a8b9f
2 changed files with 101 additions and 29 deletions

View File

@@ -15,6 +15,15 @@ using vec3 = vec<3>;
using vec4 = vec<4>; using vec4 = vec<4>;
using vec5 = vec<5>; using vec5 = vec<5>;
template<unsigned N>
using mat = std::array<std::array<float, N>, N>;
using mat1 = mat<1>;
using mat2 = mat<2>;
using mat3 = mat<3>;
using mat4 = mat<4>;
using mat5 = mat<5>;
template<class V> template<class V>
V operator*(V a, const float &b) { V operator*(V a, const float &b) {
for (auto &e : a) e *= b; for (auto &e : a) e *= b;
@@ -93,6 +102,30 @@ float dot(const V &a, const V &b) {
return sum; 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<unsigned N> template<unsigned N>
std::vector<vec<N>> mirror(const tc::Group &group) { std::vector<vec<N>> mirror(const tc::Group &group) {
std::vector<std::vector<float>> mirrors; std::vector<std::vector<float>> mirrors;
@@ -140,6 +173,15 @@ vec<N> stereo(const vec<N + 1> &v) {
return r; return r;
} }
template<unsigned N>
vec<N> ortho(const vec<N + 1> &v) {
vec<N> r;
for (int i = 0; i < N; ++i) {
r[i] = v[i];
}
return r;
}
template<class V> template<class V>
V project(const V &vec, const V &target) { V project(const V &vec, const V &target) {
return dot(vec, target) / dot(target, target) * target; return dot(vec, target) / dot(target, target) * target;
@@ -192,3 +234,21 @@ glm::mat4 utilRotate(const int u, const int v, const float theta) {
res[v][v] = std::cos(theta); res[v][v] = std::cos(theta);
return res; return res;
} }
template<unsigned N>
mat<N> identity() {
mat<N> res{};
for (int i = 0; i < N; ++i)
res[i][i] = 1;
return res;
}
template<unsigned N>
mat<N> rot(int u, int v, float theta) {
auto res = identity<N>();
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;
}

View File

@@ -31,6 +31,8 @@ struct Matrices {
glm::mat4 proj; glm::mat4 proj;
glm::mat4 view; glm::mat4 view;
Matrices() = default;
Matrices(const glm::mat4 &proj, const glm::mat4 &view) Matrices(const glm::mat4 &proj, const glm::mat4 &view)
: proj(proj), view(view) { : proj(proj), view(view) {
} }
@@ -45,49 +47,49 @@ struct State {
int dimension; int dimension;
}; };
Matrices build(GLFWwindow *window, State &state) { Matrices build(GLFWwindow *window, State &state, float shift = 0.0) {
int width, height; int width, height;
glfwGetFramebufferSize(window, &width, &height); glfwGetFramebufferSize(window, &width, &height);
auto aspect = (float) width / (float) height; auto aspect = (float) width / (float) height / 2;
auto pheight = 1.4f; auto pheight = 1.4f;
auto pwidth = aspect * pheight; auto pwidth = aspect * pheight;
glm::mat4 proj = glm::ortho(-pwidth, pwidth, -pheight, pheight, -10.0f, 10.0f); 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)) { if (!glfwGetKey(window, GLFW_KEY_LEFT_SHIFT)) {
state.st += state.time_delta / 8; state.st += state.time_delta / 8;
} }
auto view = glm::identity<glm::mat4>(); auto view = glm::identity<glm::mat4>();
if (state.dimension < 4) { return Matrices(skew * proj, view);
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);
} }
template<class C> template<class C>
std::vector<vec4> points(const tc::Group &group, const C &coords) { std::vector<vec4> points(const tc::Group &group, const C &coords, const float time) {
auto cosets = group.solve(); auto cosets = group.solve();
auto mirrors = mirror<5>(group); auto mirrors = mirror<5>(group);
auto corners = plane_intersections(mirrors); auto corners = plane_intersections(mirrors);
auto start = barycentric(corners, coords); auto start = barycentric(corners, coords);
const auto &higher = cosets.path.walk<vec5, vec5>(start, mirrors, reflect<vec5>); auto higher = cosets.path.walk<vec5, vec5>(start, mirrors, reflect<vec5>);
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<vec4> lower(higher.size()); std::vector<vec4> lower(higher.size());
std::transform(higher.begin(), higher.end(), lower.begin(), stereo<4>); std::transform(higher.begin(), higher.end(), lower.begin(), stereo<4>);
return lower; return lower;
@@ -103,7 +105,7 @@ Prop<4, vec4> make_slice(
) { ) {
Prop<N, vec4> res{}; Prop<N, vec4> res{};
res.vbo.put(points(g, coords)); // res.vbo.put(points(g, coords));
res.ibo.put(merge<N>(hull<N>(g, all_sg_gens, exclude))); res.ibo.put(merge<N>(hull<N>(g, all_sg_gens, exclude)));
res.vao.ipointer(0, res.ibo, 4, GL_UNSIGNED_INT); 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); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
std::vector<int> symbol = {5, 3, 3, 2}; std::vector<int> symbol = {4, 3, 3, 3};
vec5 root = {.80, .09, .09, 0.09, 0.03}; vec5 root = {.80, .02, .02, .02, .02};
auto group = tc::schlafli(symbol); auto group = tc::schlafli(symbol);
auto gens = generators(group); auto gens = generators(group);
@@ -262,15 +264,25 @@ void run(const std::string &config_file, GLFWwindow *window) {
int width, height; int width, height;
glfwGetFramebufferSize(window, &width, &height); glfwGetFramebufferSize(window, &width, &height);
glViewport(0, 0, width, height);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Matrices mats = build(window, state);
ubo.put(mats);
glLineWidth(1.5); 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); ren.draw(prop);
//region old renderers //region old renderers