diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/camera/camera.cpp | 12 | ||||
-rw-r--r-- | src/camera/camera.h | 4 | ||||
-rw-r--r-- | src/utils/sceneparser.cpp | 4 | ||||
-rw-r--r-- | src/vec4ops/rotations4d.cpp | 4 | ||||
-rw-r--r-- | src/vec4ops/vec4ops.cpp | 23 |
5 files changed, 40 insertions, 7 deletions
diff --git a/src/camera/camera.cpp b/src/camera/camera.cpp index b63164b..4cc9e56 100644 --- a/src/camera/camera.cpp +++ b/src/camera/camera.cpp @@ -1,6 +1,6 @@ #include <stdexcept> #include "camera.h" -#include "4dvecops/vec4ops.h" +#include "vec4ops/vec4ops.h" Camera::Camera(SceneCameraData cameraData) : m_pos(cameraData.pos), @@ -23,7 +23,15 @@ glm::mat4 Camera::getViewMatrix() const { glm::mat4 Camera::getInverseViewMatrix() const { // Optional TODO: implement the getter or make your own design - return m_inverse; + return m_inverseViewMatrix; +} + +glm::vec3 Camera::getTranslationVector() const { + return m_translationVector; +} + +glm::vec3 Camera::getInverseTranslationVector() const { + return m_inverseTranslationVector; } float Camera::getAspectRatio() const { diff --git a/src/camera/camera.h b/src/camera/camera.h index 4fa9ab0..5059655 100644 --- a/src/camera/camera.h +++ b/src/camera/camera.h @@ -16,6 +16,8 @@ public: // You might also want to define another function that return the inverse of the view matrix. glm::mat4 getViewMatrix() const; glm::mat4 getInverseViewMatrix() const; + glm::vec3 getTranslationVector() const; + glm::vec3 getInverseTranslationVector() const; // Returns the aspect ratio of the camera. float getAspectRatio() const; @@ -39,7 +41,7 @@ public: private: glm::mat4 m_viewMatrix; - glm::mat4 m_inverse; + glm::mat4 m_inverseViewMatrix; float m_heightAngle; glm::vec3 m_pos; diff --git a/src/utils/sceneparser.cpp b/src/utils/sceneparser.cpp index 6d668ff..5eddf93 100644 --- a/src/utils/sceneparser.cpp +++ b/src/utils/sceneparser.cpp @@ -1,6 +1,6 @@ #include "sceneparser.h" #include "scenefilereader.h" -#include "4dvecops/vec4ops.h" +#include "vec4ops/vec4ops.h" #include <glm/gtx/transform.hpp> #include <QImage> #include <iostream> @@ -183,4 +183,4 @@ void SceneParser::scale4( m[1][1] *= v.y; m[2][2] *= v.z; m[3][3] *= v.w; -}
\ No newline at end of file +} diff --git a/src/vec4ops/rotations4d.cpp b/src/vec4ops/rotations4d.cpp index 4943c7f..37997de 100644 --- a/src/vec4ops/rotations4d.cpp +++ b/src/vec4ops/rotations4d.cpp @@ -1,5 +1,5 @@ #include "raytracer/raytracer.h" -#include "4dvecops/vec4ops.h" +#include "vec4ops/vec4ops.h" glm::mat4 Vec4Ops::getRotationMatrix4XY( float angleRadians) { @@ -71,4 +71,4 @@ glm::mat4 Vec4Ops::getRotationMatrix4ZW( result[0][0] = 1; result[1][1] = 1; return result; -}
\ No newline at end of file +} diff --git a/src/vec4ops/vec4ops.cpp b/src/vec4ops/vec4ops.cpp index 80cebaf..458bc1f 100644 --- a/src/vec4ops/vec4ops.cpp +++ b/src/vec4ops/vec4ops.cpp @@ -1,5 +1,6 @@ #include <stdexcept> #include "vec4ops.h" +#include "settings.h" // vector operations on 4d vectors, // reference: https://hollasch.github.io/ray4/Four-Space_Visualization_of_4D_Objects.html#chapter5 @@ -36,6 +37,16 @@ glm::mat4 Vec4Ops::getViewMatrix4( glm::vec4 upVector, glm::vec4 lookVector) { + // rotation matrices for each plane + glm::mat4 rotMatrixXY = getRotationMatrix4XY(glm::radians(settings.xy)); + glm::mat4 rotMatrixXZ = getRotationMatrix4XZ(glm::radians(settings.xz)); + glm::mat4 rotMatrixYZ = getRotationMatrix4YZ(glm::radians(settings.yz)); + glm::mat4 rotMatrixXW = getRotationMatrix4XW(glm::radians(settings.xw)); + glm::mat4 rotMatrixYW = getRotationMatrix4YW(glm::radians(settings.yw)); + glm::mat4 rotMatrixZW = getRotationMatrix4ZW(glm::radians(settings.zw)); + + glm::mat4 combinedRotationMatrix = rotMatrixXY * rotMatrixYZ * rotMatrixXZ * rotMatrixXW * rotMatrixYW * rotMatrixZW; + // calculate e3 basis vector, the transformation col of view matrix if (glm::distance(fromPoint, toPoint) < 0.0001f) { throw std::runtime_error("fromPoint and toPoint are the same"); @@ -60,5 +71,17 @@ glm::mat4 Vec4Ops::getViewMatrix4( glm::vec4 e0 = cross4(e3, e2, e1); e0 = glm::normalize(e0); + // Apply the combined rotation matrix to the view basis vectors + e0 = combinedRotationMatrix * e0; + e1 = combinedRotationMatrix * e1; + e2 = combinedRotationMatrix * e2; + e3 = combinedRotationMatrix * e3; + + // Normalizing might be necessary after applying the rotation + e0 = glm::normalize(e0); + e1 = glm::normalize(e1); + e2 = glm::normalize(e2); + e3 = glm::normalize(e3); + return {e2, e1, e0, e3}; }
\ No newline at end of file |