diff --git a/.gitmodules b/.gitmodules index 4b4c1d6..5a2f5bd 100644 --- a/.gitmodules +++ b/.gitmodules @@ -8,3 +8,6 @@ [submodule "vendor/glm"] path = vendor/glm url = https://github.com/g-truc/glm.git +[submodule "vendor/versor"] + path = vendor/versor + url = https://github.com/wolftype/versor.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 6761650..6d1ac7e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,5 +14,9 @@ add_subdirectory(vendor/glfw) option(GLM_TEST_ENABLE OFF) add_subdirectory(vendor/glm) +add_subdirectory(vendor/versor) +get_property(VSR_INCLUDE_DIR GLOBAL PROPERTY VSR_INCLUDE_DIR) +target_include_directories(vsr PUBLIC ${VSR_INCLUDE_DIR}) + add_subdirectory(framework) add_subdirectory(simplex) diff --git a/simplex/CMakeLists.txt b/simplex/CMakeLists.txt index c39f5ab..af11817 100644 --- a/simplex/CMakeLists.txt +++ b/simplex/CMakeLists.txt @@ -7,6 +7,7 @@ target_link_libraries(${PROJECT_NAME} glad glm glfw + vsr framework) target_include_directories(${PROJECT_NAME} diff --git a/simplex/include/rotor.h b/simplex/include/rotor.h index 07ba8a5..979654b 100644 --- a/simplex/include/rotor.h +++ b/simplex/include/rotor.h @@ -1,80 +1,27 @@ #ifndef GL_TEMPLATE_ROTOR_H #define GL_TEMPLATE_ROTOR_H +#include #include +#include +#include -#include +glm::mat4 rotor(glm::vec4 u, glm::vec4 v, float angle) { + using Vec = vsr::euclidean_vector<4, float>; -glm::mat4 rotor_xy(float t) { - float c = cos(t); - float s = sin(t); + auto eu = *((Vec *) (void *) &u); + auto ev = *((Vec *) (void *) &v); - return glm::mat4( - +c, s, 0, 0, - -s, c, 0, 0, - +0, 0, 1, 0, - +0, 0, 0, 1 - ); -} + auto biv = (eu ^ ev).unit() * angle; -glm::mat4 rotor_xz(float t) { - float c = cos(t); - float s = sin(t); + Vec col[4] = { + Vec(1, 0, 0, 0).rotate(biv), + Vec(0, 1, 0, 0).rotate(biv), + Vec(0, 0, 1, 0).rotate(biv), + Vec(0, 0, 0, 1).rotate(biv) + }; - return glm::mat4( - +c, 0, s, 0, - +0, 1, 0, 0, - -s, 0, c, 0, - +0, 0, 0, 1 - ); -} - -glm::mat4 rotor_xw(float t) { - float c = cos(t); - float s = sin(t); - - return glm::mat4( - +c, 0, 0, s, - +0, 1, 0, 0, - +0, 0, 1, 0, - -s, 0, 0, c - ); -} - -glm::mat4 rotor_yz(float t) { - float c = cos(t); - float s = sin(t); - - return glm::mat4( - 1, +0, 0, 0, - 0, +c, s, 0, - 0, -s, c, 0, - 0, +0, 0, 1 - ); -} - -glm::mat4 rotor_yw(float t) { - float c = cos(t); - float s = sin(t); - - return glm::mat4( - 1, +0, 0, 0, - 0, +c, 0, s, - 0, +0, 1, 0, - 0, -s, 0, c - ); -} - -glm::mat4 rotor_zw(float t) { - float c = cos(t); - float s = sin(t); - - return glm::mat4( - 1, 0, +0, 0, - 0, 1, +0, 0, - 0, 0, +c, s, - 0, 0, -s, c - ); + return glm::make_mat4((float *) col); } #endif //GL_TEMPLATE_ROTOR_H diff --git a/simplex/src/main.cpp b/simplex/src/main.cpp index 0f3f3a8..8cfba21 100644 --- a/simplex/src/main.cpp +++ b/simplex/src/main.cpp @@ -113,7 +113,9 @@ class GLApp : public App { glfwGetFramebufferSize(getWindow(), &width, &height); float ratio = (float) width / height; - matrices.model = rotor_yw(getTime() / 5) * rotor_xz(getTime() / 2); + matrices.model = + rotor(glm::vec4(1,0,0,0), glm::vec4(0,0,1,0), getTime() / 4) * + rotor(glm::vec4(0,1,0,0), glm::vec4(0,0,0,1), getTime() / 4); matrices.view = glm::lookAt(glm::vec3(0, 0, -2), glm::vec3(0, 0, 0), glm::vec3(0, 1, 0)); matrices.proj = glm::perspective(1.f, ratio, 0.1f, 10.0f); diff --git a/vendor/versor b/vendor/versor new file mode 160000 index 0000000..0d9dae3 --- /dev/null +++ b/vendor/versor @@ -0,0 +1 @@ +Subproject commit 0d9dae3d716dd595b271a47590d3c43fc89fbbda