From 669d04845d5a9a003f678729f483eb923239311f Mon Sep 17 00:00:00 2001 From: David Allemang Date: Wed, 16 Feb 2022 17:13:32 -0500 Subject: [PATCH] Add toggle for colored XYZW axes --- src/main.cpp | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index c910bd6..0f66dcb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,11 +12,18 @@ #include struct State { - Eigen::Vector4f bg{0.45f, 0.55f, 0.60f, 1.00f}; + Eigen::Vector4f bg{0.07f, 0.09f, 0.10f, 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) { @@ -27,6 +34,11 @@ Eigen::Matrix4f rotor(int u, int v, float rad) { return res; } +template +T_ mix(const T_ &a, const T_ &b, const typename T_::Scalar &x) { + return a * (1 - x) + b * x; +} + void show_overlay(State &state) { static std::string gl_vendor = (const char *) glGetString(GL_VENDOR); static std::string gl_renderer = (const char *) glGetString(GL_RENDERER); @@ -71,6 +83,8 @@ void show_overlay(State &state) { ImGui::ColorEdit3("Foreground", state.fg.data(), ImGuiColorEditFlags_Float); ImGui::ColorEdit3("Wireframe", state.wf.data(), ImGuiColorEditFlags_Float); + ImGui::Checkbox("Show RGBY axis colors", &state.color_axes); + if (io.MouseDown[0] && !io.WantCaptureMouse) { Eigen::Matrix4f rot = Eigen::Matrix4f::Identity(); Eigen::Vector2f del{io.MouseDelta.x, io.MouseDelta.y}; @@ -283,11 +297,31 @@ int run(GLFWwindow *window, ImGuiContext *context) { glUseProgram(wire_pgm); glBindVertexArray(wire_vao); - glUniform4fv(0, 1, state.fg); + 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, (GLsizei) wire_dynamic.cells().size(), GL_UNSIGNED_INT, nullptr); + glBindVertexArray(0); glUseProgram(0);