aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsotech117 <michael_foiani@brown.edu>2023-12-13 15:36:52 -0500
committersotech117 <michael_foiani@brown.edu>2023-12-13 15:36:52 -0500
commit6e27cd596611758bf82f58cff25ad6310bb5ad6e (patch)
tree6794163f31433cf63475956859abebf3c2cb1fa6 /src
parent4a1527bdb10f8953fa3f387f5cb3144805541738 (diff)
add translation of camera
Diffstat (limited to 'src')
-rw-r--r--src/camera/camera.cpp6
-rw-r--r--src/vec4ops/rotations4d.cpp43
-rw-r--r--src/vec4ops/vec4ops.h3
3 files changed, 50 insertions, 2 deletions
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<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