From 6e27cd596611758bf82f58cff25ad6310bb5ad6e Mon Sep 17 00:00:00 2001 From: sotech117 Date: Wed, 13 Dec 2023 15:36:52 -0500 Subject: add translation of camera --- src/camera/camera.cpp | 6 ++++-- src/vec4ops/rotations4d.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ src/vec4ops/vec4ops.h | 3 +++ 3 files changed, 50 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/camera/camera.cpp b/src/camera/camera.cpp index fb63d77..69f2787 100644 --- a/src/camera/camera.cpp +++ b/src/camera/camera.cpp @@ -7,12 +7,14 @@ void Camera::updateViewMatrix(SceneCameraData cameraData) { m_viewMatrix = Vec4Ops::getViewMatrix4(cameraData.look, cameraData.up, cameraData.over); - // add settings.xy rotation m_viewMatrix = glm::rotate(m_viewMatrix, glm::radians(settings.xy), glm::vec3(0.f, 1.f, 0.f)); m_viewMatrix = glm::rotate(m_viewMatrix, glm::radians(settings.yz), glm::vec3(1.f, 0.f, 0.f)); m_viewMatrix = glm::rotate(m_viewMatrix, glm::radians(settings.xz), glm::vec3(0.f, 0.f, 1.f)); - m_translationVector = -cameraData.pos; + + // TODO: link sliders here. make them smaller changes since our objects are so small + glm::vec4 uiTranslation = glm::vec4(settings.xw, settings.yw, 0.f, settings.zw); + m_translationVector = -cameraData.pos + uiTranslation; m_inverseViewMatrix = glm::inverse(m_viewMatrix); m_inverseTranslationVector = -m_translationVector; 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 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 +#include 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 anglesRadians); }; #endif //PROJECTS_RAY_VEC4OPS_H -- cgit v1.2.3-70-g09d2