add versor dependency, generate rotor matrix

This commit is contained in:
2018-12-19 22:59:38 -05:00
parent 83d0ce5ef3
commit 78195ef8ec
6 changed files with 27 additions and 69 deletions

3
.gitmodules vendored
View File

@@ -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

View File

@@ -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)

View File

@@ -7,6 +7,7 @@ target_link_libraries(${PROJECT_NAME}
glad
glm
glfw
vsr
framework)
target_include_directories(${PROJECT_NAME}

View File

@@ -1,80 +1,27 @@
#ifndef GL_TEMPLATE_ROTOR_H
#define GL_TEMPLATE_ROTOR_H
#include <glm/vec4.hpp>
#include <glm/mat4x4.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <vsr/vsr.h>
#include <math.h>
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

View File

@@ -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);

1
vendor/versor vendored Submodule

Submodule vendor/versor added at 0d9dae3d71