From 1f284ed349317281506868d5f8efbbc51b644eee Mon Sep 17 00:00:00 2001 From: David Allemang Date: Fri, 27 Jan 2023 22:28:39 -0500 Subject: [PATCH] ENH: Replace GLM with Eigen --- CMakeLists.txt | 4 ++-- vendor/eigen.cmake | 10 ++++++++++ vendor/glm.cmake | 8 -------- vis/CMakeLists.txt | 2 +- vis/include/mirror.hpp | 34 +++++++++++++++++++++++++++------- vis/src/main.cpp | 14 +++++++------- 6 files changed, 47 insertions(+), 25 deletions(-) create mode 100644 vendor/eigen.cmake delete mode 100644 vendor/glm.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 35abe80..5bd3782 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,12 +4,12 @@ project(toddcox-faster) set(CMAKE_CXX_STANDARD 20) include(FetchContent) +include(vendor/eigen.cmake) include(vendor/fmt.cmake) -include(vendor/peglib.cmake) include(vendor/glad.cmake) include(vendor/glfw.cmake) -include(vendor/glm.cmake) include(vendor/gtest.cmake) +include(vendor/peglib.cmake) include(vendor/yaml-cpp.cmake) include(vendor/embed.cmake) diff --git a/vendor/eigen.cmake b/vendor/eigen.cmake new file mode 100644 index 0000000..f84f496 --- /dev/null +++ b/vendor/eigen.cmake @@ -0,0 +1,10 @@ +FetchContent_Declare( + eigen + GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git + GIT_TAG 3.4 + GIT_PROGRESS TRUE +) +set(EIGEN_BUILD_DOC OFF CACHE INTERNAL "") +set(BUILD_TESTING OFF CACHE INTERNAL "") +set(EIGEN_BUILD_PKGCONFIG OFF CACHE INTERNAL "") +FetchContent_MakeAvailable(eigen) diff --git a/vendor/glm.cmake b/vendor/glm.cmake deleted file mode 100644 index ebc1655..0000000 --- a/vendor/glm.cmake +++ /dev/null @@ -1,8 +0,0 @@ -FetchContent_Declare( - glm - GIT_REPOSITORY https://github.com/g-truc/glm.git - GIT_TAG 0.9.9.8 - GIT_PROGRESS TRUE -) - -FetchContent_MakeAvailable(glm) diff --git a/vis/CMakeLists.txt b/vis/CMakeLists.txt index 52debce..d99c423 100644 --- a/vis/CMakeLists.txt +++ b/vis/CMakeLists.txt @@ -19,5 +19,5 @@ target_include_directories(vis-util INTERFACE include) add_executable(vis src/main.cpp) target_include_directories(vis PRIVATE include) -target_link_libraries(vis PRIVATE tc glad glm glfw yaml-cpp shaders) +target_link_libraries(vis PRIVATE tc glad eigen glfw yaml-cpp shaders fmt) add_dependencies(vis presets) diff --git a/vis/include/mirror.hpp b/vis/include/mirror.hpp index 04f304e..b3af23a 100644 --- a/vis/include/mirror.hpp +++ b/vis/include/mirror.hpp @@ -6,6 +6,8 @@ #include #include +#include + template using vec = std::array; @@ -184,11 +186,29 @@ std::vector plane_intersections(std::vector normals) { return results; } -glm::mat4 utilRotate(const int u, const int v, const float theta) { - auto res = glm::identity(); - res[u][u] = std::cos(theta); - res[u][v] = std::sin(theta); - res[v][u] = -std::sin(theta); - res[v][v] = std::cos(theta); +Eigen::Matrix4f utilRotate(const int u, const int v, const float theta) { + Eigen::Matrix4f res; + res.setIdentity(); + res(u, u) = std::cos(theta); + res(u, v) = std::sin(theta); + res(v, u) = -std::sin(theta); + res(v, v) = std::cos(theta); return res; -} \ No newline at end of file +} + +Eigen::Matrix4f ortho( + float l, + float r, + float b, + float t, + float n, + float f +) { + Eigen::Matrix4f res; + res << + 2 / (r - l), 0, 0, -(r + l) / (r - l), + 0, 2 / (t - b), 0, -(t + b) / (t - b), + 0, 0, -2 / (f - n), -(f + n) / (f - n), + 0, 0, 0, 1; + return res; +} diff --git a/vis/src/main.cpp b/vis/src/main.cpp index 6a8d3bf..ae2c606 100644 --- a/vis/src/main.cpp +++ b/vis/src/main.cpp @@ -3,8 +3,6 @@ #include #include -#include - #include #include "util.hpp" @@ -28,10 +26,10 @@ __attribute__((unused)) __declspec(dllexport) int NvOptimusEnablement = 0x000000 #endif struct Matrices { - glm::mat4 proj; - glm::mat4 view; + Eigen::Matrix4f proj; + Eigen::Matrix4f view; - Matrices(const glm::mat4 &proj, const glm::mat4 &view) + Matrices(const Eigen::Matrix4f &proj, const Eigen::Matrix4f &view) : proj(proj), view(view) { } }; @@ -52,13 +50,15 @@ Matrices build(GLFWwindow *window, State &state) { auto aspect = (float) width / (float) height; auto pheight = 1.4f; auto pwidth = aspect * pheight; - glm::mat4 proj = glm::ortho(-pwidth, pwidth, -pheight, pheight, -10.0f, 10.0f); + Eigen::Matrix4f proj = ortho(-pwidth, pwidth, -pheight, pheight, -10.0f, 10.0f); if (!glfwGetKey(window, GLFW_KEY_LEFT_SHIFT)) { state.st += state.time_delta / 8; } - auto view = glm::identity(); + Eigen::Matrix4f view; + view.setIdentity(); + if (state.dimension < 4) { view *= utilRotate(2, 3, M_PI_2f32 + 0.01f); }