mirror of
https://github.com/allemangD/toddcox-visualize.git
synced 2025-11-10 12:02:47 -05:00
WIP: Render 4d geometry from file
This commit is contained in:
@@ -4,41 +4,59 @@
|
||||
#include <mirror.hpp>
|
||||
|
||||
#include <ml/meshlib.hpp>
|
||||
#include <ml/meshlib_json.hpp>
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
int main() {
|
||||
std::vector<int> symbol = {3, 4, 3, 2};
|
||||
vec5 root{0.80, 0.02, 0.02, 0.02, 0.02};
|
||||
std::vector<int> symbol = {5, 3, 3};
|
||||
vec4 root{0.80, 0.02, 0.02, 0.02};
|
||||
|
||||
|
||||
auto group = tc::schlafli(symbol);
|
||||
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 mirrors = mirror<5>(group);
|
||||
auto mirrors = mirror<4>(group);
|
||||
auto corners = plane_intersections(mirrors);
|
||||
auto start = barycentric(corners, root);
|
||||
|
||||
using Projective5f = Eigen::Transform<float, 5, Eigen::Projective>;
|
||||
Projective5f transform = Projective5f::Identity();
|
||||
using Projective = Eigen::Transform<float, 4, Eigen::Projective>;
|
||||
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(
|
||||
higher.begin(), higher.end(), higher.begin(),
|
||||
[&](const vec5 &v) {
|
||||
[&](const vec4 &v) {
|
||||
return (transform * v.homogeneous()).hnormalized();
|
||||
}
|
||||
);
|
||||
|
||||
std::vector<vec4> lower(higher.size());
|
||||
std::transform(higher.begin(), higher.end(), lower.begin(), stereo<4>);
|
||||
// std::vector<vec4> lower(higher.size());
|
||||
// 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;
|
||||
}
|
||||
|
||||
89
src/main.cpp
89
src/main.cpp
@@ -127,31 +127,36 @@ int run(GLFWwindow *window, ImGuiContext *context) {
|
||||
State state;
|
||||
|
||||
Buffer<GLuint> ind_buf;
|
||||
Buffer<Eigen::Vector3f> vert_buf;
|
||||
Buffer<Eigen::Vector4f> vert_buf;
|
||||
|
||||
Buffer<GLuint> ind4d_buf;
|
||||
Buffer<Eigen::Vector4f> vert4d_buf;
|
||||
// Buffer<GLuint> ind4d_buf;
|
||||
// Buffer<Eigen::Vector4f> vert4d_buf;
|
||||
|
||||
VertexArray<Eigen::Vector3f> vao(vert_buf);
|
||||
VertexArray<Eigen::Vector4f> vao(vert_buf);
|
||||
glVertexArrayElementBuffer(vao, ind_buf);
|
||||
|
||||
VertexArray<Eigen::Vector4f> vao4d(vert4d_buf);
|
||||
glVertexArrayElementBuffer(vao4d, ind4d_buf);
|
||||
// VertexArray<Eigen::Vector4f> vao4d(vert4d_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());
|
||||
vert_buf.upload(mesh.points.colwise());
|
||||
|
||||
auto mesh4d = ml::make_cube_wire<4>(0.33f);
|
||||
auto elements4d = (GLint) ind4d_buf.upload(mesh4d.cells.reshaped());
|
||||
vert4d_buf.upload(mesh4d.points.colwise());
|
||||
// auto mesh4d = ml::make_cube_wire<4>(0.33f);
|
||||
// auto elements4d = (GLint) ind4d_buf.upload(mesh4d.cells.reshaped());
|
||||
// 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"));
|
||||
FragmentShader fs(std::ifstream("res/shaders/main.frag.glsl"));
|
||||
|
||||
Program pgm(vs, fs);
|
||||
Program pgm4d(vs4d, fs);
|
||||
Program pgm(vs4d, fs);
|
||||
// Program pgm4d(vs4d, fs);
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
@@ -173,7 +178,7 @@ int run(GLFWwindow *window, ImGuiContext *context) {
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
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);
|
||||
glBindVertexArray(vao);
|
||||
@@ -185,34 +190,34 @@ int run(GLFWwindow *window, ImGuiContext *context) {
|
||||
glBindVertexArray(0);
|
||||
glUseProgram(0);
|
||||
|
||||
glUseProgram(pgm4d);
|
||||
glBindVertexArray(vao4d);
|
||||
glUniform4fv(0, 1, state.wf.data());
|
||||
glUniform1f(1, (GLfloat) glfwGetTime());
|
||||
glUniformMatrix4fv(2, 1, false, proj.data());
|
||||
glUniformMatrix4fv(3, 1, false, state.rot.data());
|
||||
|
||||
if (state.color_axes) {
|
||||
auto factor = 0.7f;
|
||||
auto x = mix(state.wf, state.R, factor);
|
||||
auto y = mix(state.wf, state.G, factor);
|
||||
auto z = mix(state.wf, state.B, factor);
|
||||
auto w = mix(state.wf, state.Y, factor);
|
||||
|
||||
glUniform4fv(0, 1, x.data());
|
||||
glDrawElementsBaseVertex(GL_LINES, 2, GL_UNSIGNED_INT, (void *) (sizeof(GLuint) * 0), 0);
|
||||
glUniform4fv(0, 1, y.data());
|
||||
glDrawElementsBaseVertex(GL_LINES, 2, GL_UNSIGNED_INT, (void *) (sizeof(GLuint) * 2), 0);
|
||||
glUniform4fv(0, 1, z.data());
|
||||
glDrawElementsBaseVertex(GL_LINES, 2, GL_UNSIGNED_INT, (void *) (sizeof(GLuint) * 8), 0);
|
||||
glUniform4fv(0, 1, w.data());
|
||||
glDrawElementsBaseVertex(GL_LINES, 2, GL_UNSIGNED_INT, (void *) (sizeof(GLuint) * 24), 0);
|
||||
}
|
||||
|
||||
glUniform4fv(0, 1, state.wf.data());
|
||||
glDrawElements(GL_LINES, elements4d, GL_UNSIGNED_INT, nullptr);
|
||||
glBindVertexArray(0);
|
||||
glUseProgram(0);
|
||||
// glUseProgram(pgm4d);
|
||||
// glBindVertexArray(vao4d);
|
||||
// glUniform4fv(0, 1, state.wf.data());
|
||||
// glUniform1f(1, (GLfloat) glfwGetTime());
|
||||
// glUniformMatrix4fv(2, 1, false, proj.data());
|
||||
// glUniformMatrix4fv(3, 1, false, state.rot.data());
|
||||
//
|
||||
// if (state.color_axes) {
|
||||
// auto factor = 0.7f;
|
||||
// auto x = mix(state.wf, state.R, factor);
|
||||
// auto y = mix(state.wf, state.G, factor);
|
||||
// auto z = mix(state.wf, state.B, factor);
|
||||
// auto w = mix(state.wf, state.Y, factor);
|
||||
//
|
||||
// glUniform4fv(0, 1, x.data());
|
||||
// glDrawElementsBaseVertex(GL_LINES, 2, GL_UNSIGNED_INT, (void *) (sizeof(GLuint) * 0), 0);
|
||||
// glUniform4fv(0, 1, y.data());
|
||||
// glDrawElementsBaseVertex(GL_LINES, 2, GL_UNSIGNED_INT, (void *) (sizeof(GLuint) * 2), 0);
|
||||
// glUniform4fv(0, 1, z.data());
|
||||
// glDrawElementsBaseVertex(GL_LINES, 2, GL_UNSIGNED_INT, (void *) (sizeof(GLuint) * 8), 0);
|
||||
// glUniform4fv(0, 1, w.data());
|
||||
// glDrawElementsBaseVertex(GL_LINES, 2, GL_UNSIGNED_INT, (void *) (sizeof(GLuint) * 24), 0);
|
||||
// }
|
||||
//
|
||||
// glUniform4fv(0, 1, state.wf.data());
|
||||
// glDrawElements(GL_LINES, elements4d, GL_UNSIGNED_INT, nullptr);
|
||||
// glBindVertexArray(0);
|
||||
// glUseProgram(0);
|
||||
|
||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||
glfwSwapBuffers(window);
|
||||
|
||||
Reference in New Issue
Block a user