aboutsummaryrefslogtreecommitdiff
path: root/src/camera/camera.cpp
diff options
context:
space:
mode:
authorsotech117 <michael_foiani@brown.edu>2023-12-07 16:23:20 -0500
committersotech117 <michael_foiani@brown.edu>2023-12-07 16:23:20 -0500
commitcaa765bff49d54217b75aaf0e7acf4e5392a11e4 (patch)
tree9b92914dfb88b99599e8e60e4512e9e9ea9a25db /src/camera/camera.cpp
parenta9274459443f1d560d7580a162deb581549980cb (diff)
upload base code
Diffstat (limited to 'src/camera/camera.cpp')
-rw-r--r--src/camera/camera.cpp72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/camera/camera.cpp b/src/camera/camera.cpp
new file mode 100644
index 0000000..62e8021
--- /dev/null
+++ b/src/camera/camera.cpp
@@ -0,0 +1,72 @@
+#include <stdexcept>
+#include "camera.h"
+
+Camera::Camera(SceneCameraData cameraData) :
+ m_pos(cameraData.pos),
+ m_heightAngle(cameraData.heightAngle),
+ m_focalLength(cameraData.focalLength),
+ m_aperture(cameraData.aperture)
+{
+ // VIEW MATRIX INTIALIZATION
+ // cast to 3 for dots & cross
+ glm::vec3 look3{cameraData.look.x, cameraData.look.y, cameraData.look.z};
+ glm::vec3 up3{cameraData.up.x, cameraData.up.y, cameraData.up.z};
+
+ // calculate new basis
+ glm::vec3 e0 = -glm::normalize(look3);
+ glm::vec3 e1 = glm::normalize(up3 - glm::dot(up3, e0) * e0);
+ glm::vec3 e2 = glm::cross(e1, e0);
+
+ glm::mat4 alignment
+ {
+ e2.x, e1.x, e0.x, 0.f,
+ e2.y, e1.y, e0.y, 0.f,
+ e2.z, e1.z, e0.z, 0.f,
+ 0.f, 0.f, 0.f, 1.f
+ };
+ glm::mat4 translation
+ {
+ 1.f, 0.f, 0.f, 0.f,
+ 0.f, 1.f, 0.f, 0.f,
+ 0.f, 0.f, 1.f, 0.f,
+ -cameraData.pos.x, -cameraData.pos.y, -cameraData.pos.z, 1.f
+ };
+
+ m_viewMatrix = alignment * translation;
+ m_inverse = glm::inverse(m_viewMatrix);
+}
+
+
+glm::mat4 Camera::getViewMatrix() const {
+ // Optional TODO: implement the getter or make your own design
+ return m_viewMatrix;
+}
+
+glm::mat4 Camera::getInverseViewMatrix() const {
+ // Optional TODO: implement the getter or make your own design
+ return m_inverse;
+}
+
+float Camera::getAspectRatio() const {
+ // Optional TODO: implement the getter or make your own design
+ throw std::runtime_error("not implemented");
+}
+
+float Camera::getHeightAngle() const {
+ // Optional TODO: implement the getter or make your own design
+ return m_heightAngle;
+}
+
+float Camera::getFocalLength() const {
+ // Optional TODO: implement the getter or make your own design
+ return m_focalLength;
+}
+
+float Camera::getAperture() const {
+ // Optional TODO: implement the getter or make your own design
+ return m_aperture;
+}
+
+glm::vec3 Camera::getPos() const {
+ return m_pos;
+}