diff options
| author | sotech117 <michael_foiani@brown.edu> | 2023-12-13 15:36:52 -0500 |
|---|---|---|
| committer | sotech117 <michael_foiani@brown.edu> | 2023-12-13 15:36:52 -0500 |
| commit | 6e27cd596611758bf82f58cff25ad6310bb5ad6e (patch) | |
| tree | 6794163f31433cf63475956859abebf3c2cb1fa6 /src/vec4ops | |
| parent | 4a1527bdb10f8953fa3f387f5cb3144805541738 (diff) | |
add translation of camera
Diffstat (limited to 'src/vec4ops')
| -rw-r--r-- | src/vec4ops/rotations4d.cpp | 43 | ||||
| -rw-r--r-- | src/vec4ops/vec4ops.h | 3 |
2 files changed, 46 insertions, 0 deletions
diff --git a/src/vec4ops/rotations4d.cpp b/src/vec4ops/rotations4d.cpp index 37997de..1ff43a7 100644 --- a/src/vec4ops/rotations4d.cpp +++ b/src/vec4ops/rotations4d.cpp @@ -72,3 +72,46 @@ glm::mat4 Vec4Ops::getRotationMatrix4ZW( result[1][1] = 1; return result; } + +glm::mat4 Vec4Ops::getRotationMatrix4( + std::vector<float> anglesRadians) +{ + // make the identity + glm::mat4 result = glm::mat4(0.f); + result[0][0] = 1.f; + result[1][1] = 1.f; + result[2][2] = 1.f; + result[3][3] = 1.f; + + // apply the rotations, starting with the last angle, which corresponds to ZW + if (anglesRadians.size() != 6) { + throw std::runtime_error("invalid rotation angle array"); + } + for (int i = 5; i >= 0; i--) { + switch (i) { + case 0: + result *= getRotationMatrix4XY(anglesRadians[i]) * result; + break; + case 1: + result *= getRotationMatrix4ZX(anglesRadians[i]) * result; + break; + case 2: + result *= getRotationMatrix4YZ(anglesRadians[i]) * result; + break; + case 3: + result *= getRotationMatrix4XW(anglesRadians[i]) * result; + break; + case 4: + result *= getRotationMatrix4YW(anglesRadians[i]) * result; + break; + case 5: + result *= getRotationMatrix4ZW(anglesRadians[i]) * result; + break; + default: + throw std::runtime_error("invalid rotation matrix"); + } + } + + return result; +} + diff --git a/src/vec4ops/vec4ops.h b/src/vec4ops/vec4ops.h index 796722a..f4f62f1 100644 --- a/src/vec4ops/vec4ops.h +++ b/src/vec4ops/vec4ops.h @@ -6,6 +6,7 @@ #define PROJECTS_RAY_VEC4OPS_H #include <glm/glm.hpp> +#include <vector> class Vec4Ops { public: @@ -36,6 +37,8 @@ public: static glm::vec4 inverseTransformDir4(glm::vec4 dir4, glm::mat4 inverseTransformDirectionMatrix); static glm::mat4 getViewMatrix4(glm::vec4 upVector, glm::vec4 lookVector, glm::vec4 overVector); + + static glm::mat4 getRotationMatrix4(std::vector<float> anglesRadians); }; #endif //PROJECTS_RAY_VEC4OPS_H |
