WIP: Render 4d geometry from file

This commit is contained in:
David Allemang
2022-02-24 16:31:40 -05:00
parent 160f978e7e
commit d99e824a06
3 changed files with 79 additions and 56 deletions

View File

@@ -41,4 +41,4 @@ add_executable(combotest src/combotest.cpp)
target_link_libraries(combotest eigen tc) target_link_libraries(combotest eigen tc)
add_executable(geometrytest src/geometrytest.cpp) add_executable(geometrytest src/geometrytest.cpp)
target_link_libraries(geometrytest eigen tc) target_link_libraries(geometrytest eigen tc nlohmann_json)

View File

@@ -4,41 +4,59 @@
#include <mirror.hpp> #include <mirror.hpp>
#include <ml/meshlib.hpp> #include <ml/meshlib.hpp>
#include <ml/meshlib_json.hpp>
#include <fstream>
#include <iostream> #include <iostream>
int main() { int main() {
std::vector<int> symbol = {3, 4, 3, 2}; std::vector<int> symbol = {5, 3, 3};
vec5 root{0.80, 0.02, 0.02, 0.02, 0.02}; vec4 root{0.80, 0.02, 0.02, 0.02};
auto group = tc::schlafli(symbol); auto group = tc::schlafli(symbol);
auto gens = generators(group); 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 cosets = group.solve();
auto mirrors = mirror<5>(group); auto mirrors = mirror<4>(group);
auto corners = plane_intersections(mirrors); auto corners = plane_intersections(mirrors);
auto start = barycentric(corners, root); auto start = barycentric(corners, root);
using Projective5f = Eigen::Transform<float, 5, Eigen::Projective>; using Projective = Eigen::Transform<float, 4, Eigen::Projective>;
Projective5f transform = Projective5f::Identity(); Projective transform = Projective::Identity();
auto higher = cosets.path.walk<vec5, vec5>(start, mirrors, reflect<vec5>); auto higher = cosets.path.walk<vec4, vec4>(start, mirrors, reflect<vec4>);
std::transform( std::transform(
higher.begin(), higher.end(), higher.begin(), higher.begin(), higher.end(), higher.begin(),
[&](const vec5 &v) { [&](const vec4 &v) {
return (transform * v.homogeneous()).hnormalized(); return (transform * v.homogeneous()).hnormalized();
} }
); );
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>);
// const auto &verts = lower;
const auto &verts = lower; const auto &verts = higher;
std::cout << inds.rows() << " " << inds.cols() << std::endl; using PT = Eigen::Matrix<float, 4, Eigen::Dynamic>;
using CT = Eigen::Matrix<unsigned, 3, Eigen::Dynamic>;
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; return EXIT_SUCCESS;
} }

View File

@@ -127,31 +127,36 @@ int run(GLFWwindow *window, ImGuiContext *context) {
State state; State state;
Buffer<GLuint> ind_buf; Buffer<GLuint> ind_buf;
Buffer<Eigen::Vector3f> vert_buf; Buffer<Eigen::Vector4f> vert_buf;
Buffer<GLuint> ind4d_buf; // Buffer<GLuint> ind4d_buf;
Buffer<Eigen::Vector4f> vert4d_buf; // Buffer<Eigen::Vector4f> vert4d_buf;
VertexArray<Eigen::Vector3f> vao(vert_buf); VertexArray<Eigen::Vector4f> vao(vert_buf);
glVertexArrayElementBuffer(vao, ind_buf); glVertexArrayElementBuffer(vao, ind_buf);
VertexArray<Eigen::Vector4f> vao4d(vert4d_buf); // VertexArray<Eigen::Vector4f> vao4d(vert4d_buf);
glVertexArrayElementBuffer(vao4d, ind4d_buf); // glVertexArrayElementBuffer(vao4d, ind4d_buf);
auto mesh = ml::make_cube(0.22f); using PointsType = Eigen::Matrix<float, 4, Eigen::Dynamic>;
using CellsType = Eigen::Matrix<unsigned, 3, Eigen::Dynamic>;
using Mesh = ml::Mesh<PointsType, CellsType>;
auto mesh = ml::read<Mesh>(std::ifstream("dodeca.pak"));
// auto mesh = ml::make_cube(0.22f);
auto elements = (GLint) ind_buf.upload(mesh.cells.reshaped()); auto elements = (GLint) ind_buf.upload(mesh.cells.reshaped());
vert_buf.upload(mesh.points.colwise()); vert_buf.upload(mesh.points.colwise());
auto mesh4d = ml::make_cube_wire<4>(0.33f); // auto mesh4d = ml::make_cube_wire<4>(0.33f);
auto elements4d = (GLint) ind4d_buf.upload(mesh4d.cells.reshaped()); // auto elements4d = (GLint) ind4d_buf.upload(mesh4d.cells.reshaped());
vert4d_buf.upload(mesh4d.points.colwise()); // 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")); VertexShader vs4d(std::ifstream("res/shaders/4d.vert.glsl"));
FragmentShader fs(std::ifstream("res/shaders/main.frag.glsl")); FragmentShader fs(std::ifstream("res/shaders/main.frag.glsl"));
Program pgm(vs, fs); Program pgm(vs4d, fs);
Program pgm4d(vs4d, fs); // Program pgm4d(vs4d, fs);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
@@ -173,7 +178,7 @@ int run(GLFWwindow *window, ImGuiContext *context) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
auto aspect = (float) display_h / (float) display_w; 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); glUseProgram(pgm);
glBindVertexArray(vao); glBindVertexArray(vao);
@@ -185,34 +190,34 @@ int run(GLFWwindow *window, ImGuiContext *context) {
glBindVertexArray(0); glBindVertexArray(0);
glUseProgram(0); glUseProgram(0);
glUseProgram(pgm4d); // glUseProgram(pgm4d);
glBindVertexArray(vao4d); // glBindVertexArray(vao4d);
glUniform4fv(0, 1, state.wf.data()); // glUniform4fv(0, 1, state.wf.data());
glUniform1f(1, (GLfloat) glfwGetTime()); // glUniform1f(1, (GLfloat) glfwGetTime());
glUniformMatrix4fv(2, 1, false, proj.data()); // glUniformMatrix4fv(2, 1, false, proj.data());
glUniformMatrix4fv(3, 1, false, state.rot.data()); // glUniformMatrix4fv(3, 1, false, state.rot.data());
//
if (state.color_axes) { // if (state.color_axes) {
auto factor = 0.7f; // auto factor = 0.7f;
auto x = mix(state.wf, state.R, factor); // auto x = mix(state.wf, state.R, factor);
auto y = mix(state.wf, state.G, factor); // auto y = mix(state.wf, state.G, factor);
auto z = mix(state.wf, state.B, factor); // auto z = mix(state.wf, state.B, factor);
auto w = mix(state.wf, state.Y, factor); // auto w = mix(state.wf, state.Y, factor);
//
glUniform4fv(0, 1, x.data()); // glUniform4fv(0, 1, x.data());
glDrawElementsBaseVertex(GL_LINES, 2, GL_UNSIGNED_INT, (void *) (sizeof(GLuint) * 0), 0); // glDrawElementsBaseVertex(GL_LINES, 2, GL_UNSIGNED_INT, (void *) (sizeof(GLuint) * 0), 0);
glUniform4fv(0, 1, y.data()); // glUniform4fv(0, 1, y.data());
glDrawElementsBaseVertex(GL_LINES, 2, GL_UNSIGNED_INT, (void *) (sizeof(GLuint) * 2), 0); // glDrawElementsBaseVertex(GL_LINES, 2, GL_UNSIGNED_INT, (void *) (sizeof(GLuint) * 2), 0);
glUniform4fv(0, 1, z.data()); // glUniform4fv(0, 1, z.data());
glDrawElementsBaseVertex(GL_LINES, 2, GL_UNSIGNED_INT, (void *) (sizeof(GLuint) * 8), 0); // glDrawElementsBaseVertex(GL_LINES, 2, GL_UNSIGNED_INT, (void *) (sizeof(GLuint) * 8), 0);
glUniform4fv(0, 1, w.data()); // glUniform4fv(0, 1, w.data());
glDrawElementsBaseVertex(GL_LINES, 2, GL_UNSIGNED_INT, (void *) (sizeof(GLuint) * 24), 0); // glDrawElementsBaseVertex(GL_LINES, 2, GL_UNSIGNED_INT, (void *) (sizeof(GLuint) * 24), 0);
} // }
//
glUniform4fv(0, 1, state.wf.data()); // glUniform4fv(0, 1, state.wf.data());
glDrawElements(GL_LINES, elements4d, GL_UNSIGNED_INT, nullptr); // glDrawElements(GL_LINES, elements4d, GL_UNSIGNED_INT, nullptr);
glBindVertexArray(0); // glBindVertexArray(0);
glUseProgram(0); // glUseProgram(0);
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
glfwSwapBuffers(window); glfwSwapBuffers(window);