mirror of
https://github.com/allemangD/toddcox-visualize.git
synced 2025-11-10 03:52:48 -05:00
pointrenderer class
This commit is contained in:
@@ -1,15 +1,13 @@
|
|||||||
#version 440
|
#version 440
|
||||||
|
|
||||||
//layout(location=1) uniform float time;
|
layout(location=1) uniform float time;
|
||||||
layout(location=2) uniform mat4 proj;
|
layout(location=2) uniform mat4 proj;
|
||||||
//layout(location=3) uniform mat4 rot;
|
layout(location=3) uniform mat4 view;
|
||||||
|
|
||||||
layout(location=0) in vec4 pos;
|
layout(location=0) in vec4 pos;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
// mat3 rot3 = mat3(rot);
|
vec3 pos3 = (view * pos).xyz;
|
||||||
// vec3 pos3 = rot3 * pos;
|
|
||||||
|
|
||||||
vec3 pos3 = pos.xyz;
|
|
||||||
gl_Position = proj * vec4(pos3, 1.0);
|
gl_Position = proj * vec4(pos3, 1.0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,20 +19,7 @@
|
|||||||
|
|
||||||
#include <geo/mirror.hpp>
|
#include <geo/mirror.hpp>
|
||||||
|
|
||||||
struct State {
|
#include "render/pointrender.hpp"
|
||||||
Eigen::Vector4f bg{0.169f, 0.169f, 0.169f, 1.00f};
|
|
||||||
Eigen::Vector4f fg{0.71f, 0.53f, 0.94f, 1.00f};
|
|
||||||
Eigen::Vector4f wf{0.95f, 0.95f, 0.95f, 1.00f};
|
|
||||||
|
|
||||||
Eigen::Vector4f R{1.00f, 0.00f, 0.00f, 1.00f};
|
|
||||||
Eigen::Vector4f G{0.00f, 1.00f, 0.00f, 1.00f};
|
|
||||||
Eigen::Vector4f B{0.00f, 0.00f, 1.00f, 1.00f};
|
|
||||||
Eigen::Vector4f Y{1.20f, 1.20f, 0.00f, 1.00f};
|
|
||||||
|
|
||||||
Eigen::Matrix4f rot = Eigen::Matrix4f::Identity();
|
|
||||||
|
|
||||||
bool color_axes = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
Eigen::Matrix4f rotor(int u, int v, float rad) {
|
Eigen::Matrix4f rotor(int u, int v, float rad) {
|
||||||
Eigen::Matrix4f res = Eigen::Matrix4f::Identity();
|
Eigen::Matrix4f res = Eigen::Matrix4f::Identity();
|
||||||
@@ -89,9 +76,9 @@ void show_overlay(State &state) {
|
|||||||
|
|
||||||
ImGui::ColorEdit3("Background", state.bg.data(), ImGuiColorEditFlags_Float);
|
ImGui::ColorEdit3("Background", state.bg.data(), ImGuiColorEditFlags_Float);
|
||||||
ImGui::ColorEdit3("Foreground", state.fg.data(), ImGuiColorEditFlags_Float);
|
ImGui::ColorEdit3("Foreground", state.fg.data(), ImGuiColorEditFlags_Float);
|
||||||
ImGui::ColorEdit3("Wireframe", state.wf.data(), ImGuiColorEditFlags_Float);
|
// ImGui::ColorEdit3("Wireframe", state.wf.data(), ImGuiColorEditFlags_Float);
|
||||||
|
|
||||||
ImGui::Checkbox("Show RGBY axis colors", &state.color_axes);
|
// ImGui::Checkbox("Show RGBY axis colors", &state.color_axes);
|
||||||
|
|
||||||
if (io.MouseDown[0] && !io.WantCaptureMouse) {
|
if (io.MouseDown[0] && !io.WantCaptureMouse) {
|
||||||
Eigen::Matrix4f rot = Eigen::Matrix4f::Identity();
|
Eigen::Matrix4f rot = Eigen::Matrix4f::Identity();
|
||||||
@@ -112,7 +99,7 @@ void show_overlay(State &state) {
|
|||||||
rot = rx * ry;
|
rot = rx * ry;
|
||||||
}
|
}
|
||||||
|
|
||||||
state.rot = rot * state.rot;
|
state.view = rot * state.view;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
@@ -131,37 +118,28 @@ void set_style() {
|
|||||||
int run(GLFWwindow *window, ImGuiContext *context) {
|
int run(GLFWwindow *window, ImGuiContext *context) {
|
||||||
State state;
|
State state;
|
||||||
|
|
||||||
// Buffer<GLuint> ind_buf;
|
PointRenderer<Eigen::Vector4f> point_render;
|
||||||
Buffer<Eigen::Vector4f> vert_buf;
|
|
||||||
|
|
||||||
VertexArray<Eigen::Vector4f> vao(vert_buf);
|
{
|
||||||
// glVertexArrayElementBuffer(vao, ind_buf);
|
tc::Group group = tc::coxeter("3 4 3");
|
||||||
|
Eigen::Vector4f coords{1, 1, 1, 1};
|
||||||
|
|
||||||
tc::Group group = tc::coxeter("3 4 3");
|
auto cosets = tc::solve(group, {}, 1000000);
|
||||||
|
|
||||||
auto cosets = solve(group, {}, 1000000);
|
auto mirrors = mirror<4>(group);
|
||||||
vec4 coords {1, 1, 1, 1};
|
|
||||||
|
|
||||||
auto mirrors = mirror<4>(group);
|
auto corners = plane_intersections(mirrors);
|
||||||
|
auto start = barycentric(corners, coords);
|
||||||
|
start.normalize();
|
||||||
|
|
||||||
auto corners = plane_intersections(mirrors);
|
auto points = cosets.path.walk<vec4, vec4>(start, mirrors, reflect<vec4>);
|
||||||
auto start = barycentric(corners, coords);
|
|
||||||
start.normalize();
|
|
||||||
|
|
||||||
auto points = cosets.path.walk<vec4, vec4>(start, mirrors, reflect<vec4>);
|
point_render.upload(points);
|
||||||
|
}
|
||||||
vert_buf.upload(points);
|
|
||||||
|
|
||||||
VertexShader vs(std::ifstream("res/shaders/main.vert.glsl"));
|
|
||||||
FragmentShader fs(std::ifstream("res/shaders/main.frag.glsl"));
|
|
||||||
|
|
||||||
Program pgm(vs, fs);
|
|
||||||
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glPointSize(2);
|
glPointSize(2);
|
||||||
|
|
||||||
Eigen::Projective3f proj;
|
|
||||||
|
|
||||||
while (!glfwWindowShouldClose(window)) {
|
while (!glfwWindowShouldClose(window)) {
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
|
|
||||||
@@ -178,17 +156,9 @@ 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, -0.6);
|
state.proj = Eigen::AlignedScaling3f(aspect, 1.0, -0.6);
|
||||||
|
|
||||||
glUseProgram(pgm);
|
point_render.draw(state);
|
||||||
glBindVertexArray(vao);
|
|
||||||
glUniform4fv(0, 1, state.fg.data());
|
|
||||||
glUniform1f(1, (GLfloat) glfwGetTime());
|
|
||||||
glUniformMatrix4fv(2, 1, false, proj.data());
|
|
||||||
glUniformMatrix4fv(3, 1, false, state.rot.data());
|
|
||||||
glDrawArrays(GL_POINTS, 0, points.size());
|
|
||||||
glBindVertexArray(0);
|
|
||||||
glUseProgram(0);
|
|
||||||
|
|
||||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
|
|||||||
53
vis/src/render/pointrender.hpp
Normal file
53
vis/src/render/pointrender.hpp
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <gl/debug.hpp>
|
||||||
|
#include <gl/buffer.hpp>
|
||||||
|
#include <gl/shader.hpp>
|
||||||
|
#include <gl/vertexarray.hpp>
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
struct State {
|
||||||
|
Eigen::Vector4f bg{0.16, 0.16, 0.16, 1.00};
|
||||||
|
Eigen::Vector4f fg{0.71, 0.53, 0.94, 1.00};
|
||||||
|
|
||||||
|
float time = 0;
|
||||||
|
|
||||||
|
Eigen::Projective3f proj = Eigen::Projective3f::Identity();
|
||||||
|
Eigen::Projective3f view = Eigen::Projective3f::Identity();
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename V_=Eigen::Vector4f>
|
||||||
|
struct PointRenderer {
|
||||||
|
using Vertex = V_;
|
||||||
|
|
||||||
|
VertexShader vs{std::ifstream("res/shaders/main.vert.glsl")};
|
||||||
|
FragmentShader fs{std::ifstream("res/shaders/main.frag.glsl")};
|
||||||
|
|
||||||
|
Program pgm{vs, fs};
|
||||||
|
|
||||||
|
Buffer<Vertex> vbo;
|
||||||
|
VertexArray<Vertex> vao{vbo};
|
||||||
|
|
||||||
|
GLuint count;
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void upload(const T &points) {
|
||||||
|
count = vbo.upload(points);
|
||||||
|
|
||||||
|
// Buffer<GLuint> ind_buf;
|
||||||
|
// glVertexArrayElementBuffer(vao, ind_buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
void draw(const State &state) {
|
||||||
|
glUseProgram(pgm);
|
||||||
|
glBindVertexArray(vao);
|
||||||
|
glUniform4fv(0, 1, state.fg.data());
|
||||||
|
glUniform1f(1, state.time);
|
||||||
|
glUniformMatrix4fv(2, 1, false, state.proj.data());
|
||||||
|
glUniformMatrix4fv(3, 1, false, state.view.data());
|
||||||
|
glDrawArrays(GL_POINTS, 0, count);
|
||||||
|
glBindVertexArray(0);
|
||||||
|
glUseProgram(0);
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user