allow higher dimensions in mirror solver

This commit is contained in:
2020-01-08 23:43:40 -05:00
parent fb33a78718
commit eec9c0b0d8
3 changed files with 43 additions and 16 deletions

2
vendor/toddcox vendored

View File

@@ -20,28 +20,49 @@ float dot(int n, const glm::vec4 &a, const glm::vec4 &b) {
return sum; return sum;
} }
float dot(int n, const std::vector<float> &a, const std::vector<float> &b) {
float sum = 0;
for (int i = 0; i < n; ++i) {
sum += a[i] * b[i];
}
return sum;
}
std::vector<glm::vec4> mirror(const tc::Group &group) { std::vector<glm::vec4> mirror(const tc::Group &group) {
std::vector<glm::vec4> mirrors; std::vector<std::vector<float>> mirrors;
for (int p = 0; p < group.ngens; ++p) { for (int p = 0; p < group.ngens; ++p) {
glm::vec4 vp{}; std::vector<float> vp;
for (int m = 0; m < p; ++m) { for (int m = 0; m < p; ++m) {
glm::vec4 vq = mirrors[m]; auto &vq = mirrors[m];
vp[m] = (cos(M_PI / group.get(p, m)) - dot(m, vp, vq)) / vq[m]; vp.push_back((cos(M_PI / group.get(p, m)) - dot(m, vp, vq)) / vq[m]);
} }
vp[p] = std::sqrt(1 - glm::dot(vp, vp)); vp.push_back(std::sqrt(1 - dot(p, vp, vp)));
for (const auto &v : mirrors) { for (const auto &v : mirrors) {
if (glm::dot(vp, v) > 0) { if (dot(p, vp, vp) > 0) {
vp *= -1; for (auto &e : vp) {
e *= -1;
}
break; break;
} }
} }
mirrors.push_back(round(vp, 15)); mirrors.push_back(vp);
} }
return mirrors; std::vector<glm::vec4> res;
for (const auto &vec : mirrors) {
glm::vec4 rvec{};
// ortho proj
for (int i = 0; i < std::min(vec.size(), 4LU); ++i) {
rvec[i] = vec[i];
}
res.push_back(rvec);
}
return res;
} }
glm::vec4 project(const glm::vec4 &vec, const glm::vec4 &target) { glm::vec4 project(const glm::vec4 &vec, const glm::vec4 &target) {

View File

@@ -56,8 +56,8 @@ int main(int argc, char *argv[]) {
"void main() {" "void main() {"
" int i = gl_VertexID;" " int i = gl_VertexID;"
" vpos = view * pos;" " vpos = view * pos;"
// " gl_Position = proj * vec4(vpos.xyz / (1), 1);" " gl_Position = proj * vec4(vpos.xyz / (1), 1);"
" gl_Position = proj * vec4(vpos.xyz / (1 - vpos.w), 1);" // " gl_Position = proj * vec4(vpos.xyz / (1 - vpos.w), 1);"
" gl_PointSize = 5;" " gl_PointSize = 5;"
"}"; "}";
@@ -71,6 +71,7 @@ int main(int argc, char *argv[]) {
"" ""
"void main() {" "void main() {"
" float d = smoothstep(-2, 2, vpos.z);" " float d = smoothstep(-2, 2, vpos.z);"
" vec3 off = 1.04 * vec3(0, 2, 4) + 2 * vec3(vpos.w);"
" color = vec4(c * d, 1);" " color = vec4(c * d, 1);"
"}"; "}";
@@ -107,12 +108,17 @@ int main(int argc, char *argv[]) {
} }
//endregion //endregion
auto group = tc::group::B(4); auto group = tc::group::H(3);
auto res = group.solve(); auto res = group.solve();
auto mirrors = mirror(group); auto mirrors = mirror(group);
auto corners = plane_intersections(mirrors); std::cout << "Solved " << res.size() << std::endl;
std::cout << "Mirror lengths:" << std::endl;
for (const auto &m : mirrors) {
std::cout << glm::length(m) << " (" << m.x << " " << m.y << " " << m.z << " " << m.w << ")" << std::endl;
}
auto start = barycentric(corners, {1.00f, 0.50f, 0.50f, 0.50f}); auto corners = plane_intersections(mirrors);
auto start = barycentric(corners, {1.00, 1.00, 1.00, 1.00});
auto points = res.path.walk<glm::vec4, glm::vec4>(start, mirrors, reflect); auto points = res.path.walk<glm::vec4, glm::vec4>(start, mirrors, reflect);
GLuint vbo; GLuint vbo;
@@ -139,7 +145,7 @@ int main(int argc, char *argv[]) {
auto aspect = (float) width / (float) height; auto aspect = (float) width / (float) height;
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); glm::mat4 proj = glm::ortho(-pwidth, pwidth, -pheight, pheight, -100.0f, 100.0f);
glUniformMatrix4fv(0, 1, false, glm::value_ptr(proj)); glUniformMatrix4fv(0, 1, false, glm::value_ptr(proj));
auto t = (float) glfwGetTime() / 3; auto t = (float) glfwGetTime() / 3;